there is a text in file, made of strings. I need to delete unnecessary spaces from every string (in the beginning, in the end of the string and between the words should leave only one). Result must be written in another file.
I've tried to do that different ways, but I always come out with the same output: everything is written in one line, even if input file is written in two or more
it seems like programm gets everything in one stream
how can i do it different way?
CODE
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string stroka;
ifstream in;
ofstream out;
in.open("c:\\borland\\my files\\files for reading\\input.txt");
out.open("c:\\borland\\my files\\files for reading\\output.txt");
if((!in)||(!out))
{
cerr<<"Unable to open file.";
exit (1);
}
while (in>>stroka)
out<<stroka<<' ';
return 0;
}
There is another way here
CODE
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int i;
string stroka[10];
ifstream in;
ofstream out;
in.open("c:\\borland\\my files\\files for reading\\input.txt");
out.open("c:\\borland\\my files\\files for reading\\output.txt");
if((!in)||(!out))
{
cerr<<"Unable to open file.";
exit (1);
}
for (i=0;i<10;i++)
{in>>stroka[i];
out<<stroka[i]<<' ';}
return 0;
}