i made this easy code to try this fstream file ("....txt")
but the file stays empty !
can someone please help ?
(note that i have a "selfmade" header file that includes all the files i normally use and the namespace)
This small programm should cout everything from the File.txt and then give you the chance to type new lines to the file, to break the cin progress you use break. but like i said the file stays empty
#include <myHead.h>
int main()
{
string line;
int i;
fstream myFile ("File.txt");
if (myFile.is_open())
{
while (getline(myFile,line))
{
cout << line << "\n";
}
line = "0";
for(line;line!="break";cin >> line)
{
if(line != "break")
myFile << line;
}
myFile.close();
}
else
cout << "error, File.txt cannot be opened!";
getch();
return 0;
}