I have to write a c++ programm with QtCreator to evaluate a football table. The results of every game is saved in a text file ("Bundesliga.txt"). We have to use fstream to read the file, but I can't open it. Here is my test programm to read the file.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
char test[10];
ifstream table;
table.open("Bundesliga.txt");
if (table.fail())
{
cerr << "Error Opening File \n";
exit(1);
}
table.getline(test, 10);
cout << test;
return 0;
}
The textfile is saved in the project folder and I imported the file as RESOURCES and OTHER_FILES. Nothing worked. I'm glad for evey single help!
I'm using Qt-Creator.
Pay attention to the following:
.txt
file must be within the source code file's folder.Bundesliaga.txt
, it's interpreted to Bundesliga.txt.txt
. This is a common mistake.if(!table.is_open())
\0
. Do that or use table >> setw(10)
. setw is declared at <iomanip>
and nulls the string with \0
.