R
Robin
// Pls note that test.txt exists.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream fs("test.txt", ios_base::in | ios_base::app);
if(!fs)
{
cout << "Error while opening file!" << endl;
return 1;
}
string s;
getline(fs, s);
cout << s << endl;
fs << "hello" << endl;
return 0;
}
The output is always "Error while opening file!" even when test.txt
exists. What's the problem?
System: Linux 2.6.20-2-generic, Complier: GCC 4.1.2
Thanks very much for your attention.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream fs("test.txt", ios_base::in | ios_base::app);
if(!fs)
{
cout << "Error while opening file!" << endl;
return 1;
}
string s;
getline(fs, s);
cout << s << endl;
fs << "hello" << endl;
return 0;
}
The output is always "Error while opening file!" even when test.txt
exists. What's the problem?
System: Linux 2.6.20-2-generic, Complier: GCC 4.1.2
Thanks very much for your attention.