Search code examples
qtqt5fstream

fstream doesn't work in Qt


I have some code working when I compile it with Code Blocks, so now that I want to use it in Qt5, I copied it. And it is doing nothing. i can run the application, but I can not read data out of my .txt file. I included fstream, string, iostream and 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;

What am I doing wrong?


Solution

  • When you compile your project a folder with the project name and the build rules should appear, which has "Release" and "Debug" as sub folders. Copy the txt into that folder, NOT in the sub folders. The folder name should look similiar to this:

    myproject-build-desktop-Qt_4_7_4_for_Desktop_-_MSVC2008__Qt_SDK__Debug