【发布时间】:2017-07-30 10:31:18
【问题描述】:
VS Express 2015 C++ 中的 fstream、ifstream 和 ofstream 根本不适合我。我试图在 MingGW 中打开一个文件,这当然可以,但在 VS Studio 中它不想打开给定位置的文件。我还将文件“Artikel.txt”放在项目根目录中,但没有任何区别。 尝试使用 errno 检测错误,失败。我也无法在输出中收到错误消息。
void App1::MainPage::initArtikel()
{
ifstream file;
file.open(L"C:\\Users\\...\\Documents\\Visual Studio 2015\\Projects\\App1\\Artikel.txt");
string zeile;
Artikel neuerArtikel;
if (file.is_open())
{
OutputDebugStringW(L"Artikel.csv wird geöffnet...");
while (getline(file, zeile))
{
size_t pos = 0;
string token;
//Erste Spalte "Name"
pos = zeile.find(CSV_DELIM);
token = zeile.substr(0, pos);
neuerArtikel.Name = stops(token);
zeile.erase(0, pos + 1);
//Zweite Spalte "Preis"
pos = zeile.find(CSV_DELIM);
token = zeile.substr(0, pos);
neuerArtikel.Preis = stod(token);
zeile.erase(0, pos + 1);
sortiment.push_back(neuerArtikel);
}
//file.close();
}
else
{
OutputDebugStringA(strerror(errno));
}
}
【问题讨论】:
-
尝试打开它以提供宽字符串路径。可能路径包含非 Unicode 符号。
-
检查来自
errno的错误代码。 -
请edit您的问题并添加相关信息。评论不适合状态更新。
标签: c++ visual-studio-2015 fstream ifstream ofstream