Hey all..i am writing a program in which im using fstream to input and output.
i dont understand how i can get and write inputs in file taking strings with whitespaces and line breaks.
First of all you should post the code. I don't really know what you want to do.
In any case, here's an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include<iostream>
#include<fstream>
#include<cstring>
usingnamespace std;
ifstream f("filename.in");
ofstream g("otherfilename.out");
int main()
{ cout<<"Enter a string: "; char x[100];
cin.getline(x, 100);
g<<x; // now you write in file named "otherfilename.out" the string x
f.close();
g.close();
return (0);
}
If is something in the first file, (the file named "filename.in") you can read from it like this:
1 2 3 4
while(!=f.eof())
{ cin>>x;
//other stuff...
}
I didn't compile the code so there may be some errors i think.
You have to be more exactely. What do you mean by "do line breaks"? You want to write more lines in a file? If so, you can put the all procedure in a loop, like this: