gpt4 book ai didi

c++ - VS Express 2015 Win10 应用程序 - ifstream 无法打开文件

转载 作者:太空宇宙 更新时间:2023-11-04 12:58:34 25 4
gpt4 key购买 nike

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));
}
}

最佳答案

在我的例子中 OutputDebugStringA(strerror(errno)); 提供:

'Permission denied'

如果我使用 file.open(Artikel.csv"); 然后我得到以下错误:

'No such file or directory'

实际将文件“Artikel.csv”放在位置:

C:\Users\ ...\Documents\Visual Studio 2015\Projects\App1\Debug\App1\AppX

给我输出:

'Artikel.csv wird geöffnet'

关于c++ - VS Express 2015 Win10 应用程序 - ifstream 无法打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45398859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com