Can Some one help me the problem with this code ? I am getting bunch of garbage value !
fstream fs("hello.txt");
if(fs.is_open())
{
string s="hello";
string line;
fs<<s;
while(getline(fs,line))
{
cout<<line;
}
cin.get();
}
fs.close();
Thank you very much but when I try to do this I am getting same garbage. I am trying to rewrite the first hello with world and trying to print that line
fstream fs("hello.txt");
if(fs.is_open())
{
string s="hello";
string line;
fs<<s<<endl;
fs.seekg(0);
fs<<"world"<<endl;
fs.seekg(0);
while(getline(fs,line))
{
cout<<line;
}
cin.get();
}
fs.close();