fstream 在 Qt 中不起作用
fstream doesn't work in Qt
当我用代码块编译时,我有一些代码可以工作,
所以现在我想在Qt5中使用它,我就复制了它。它什么都不做。我可以 运行 应用程序,但无法从 .txt
文件中读取数据。
我包括了 fstream、string、iostream 和 QCoreApplication。
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;
我做错了什么?
当您编译项目时,应该会出现一个包含项目名称和构建规则的文件夹,其中包含 "Release" 和 "Debug" 作为子文件夹。将 txt 复制到该文件夹中,而不是子文件夹中。
文件夹名称应与此类似:
myproject-build-desktop-Qt_4_7_4_for_Desktop_-_MSVC2008__Qt_SDK__Debug
当我用代码块编译时,我有一些代码可以工作,
所以现在我想在Qt5中使用它,我就复制了它。它什么都不做。我可以 运行 应用程序,但无法从 .txt
文件中读取数据。
我包括了 fstream、string、iostream 和 QCoreApplication。
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;
我做错了什么?
当您编译项目时,应该会出现一个包含项目名称和构建规则的文件夹,其中包含 "Release" 和 "Debug" 作为子文件夹。将 txt 复制到该文件夹中,而不是子文件夹中。 文件夹名称应与此类似:
myproject-build-desktop-Qt_4_7_4_for_Desktop_-_MSVC2008__Qt_SDK__Debug