0
当我用代码块编译代码时,我有一些代码工作,所以现在我想在Qt5中使用它,我复制了它。它什么都不做。我可以运行该应用程序,但无法从我的.txt
文件中读取数据。我包括fstream,字符串,iostream和QCoreApplication。fstream在Qt中不起作用
fstream data;
data.open("Datenbank.txt",ios::in);
//Variables for Database
string DbName,ServerName,UserName,Password,Rolename,Charset,Parameters;
string NewForeName ="Alex";
// reading txt Data
data>>DbName;
data>>ServerName;
data>>UserName;
data>>Password;
data>>Rolename;
data>>Charset;
data>>Parameters;
cout<<"test"<<endl;
data.close();
cout<<DbName<<endl;
cout<<ServerName<<endl;
cout<<UserName<<endl;
cout<<Password<<endl;
cout<<"test2"<<endl;
我在做什么错?
你尝试过调试?此外,您似乎并未检查文件是否已成功打开。我很肯定你只是没有在正确的地方的文件,它只是无法打开文件,由于这一点。为data.open()函数添加失败检查,使用is_open()或失败()/ good()并报告回来。 –
项目和Datenbank.txt在哪里?如果你使用的是Qt Creator,那么你应该知道Qt Creator为二进制文件创建单独的目录build -.....。也许你只是指定了错误的路径 –
你正在使用相对路径,可能是你的项目的输出目录不包含Datebank.txt文件 –