Witam, piszę program, który ma pobrać dane z pliku txt, usunąć z niego podwójne spacje i wczytać na nowo poprawionego
Mam Problem przy usuwaniu podwójnych spacji, którego do końca nie rozumiem, bo wydaje mi się, że dobrze to napisałem.
Treść pliku: malo nas do pieczenia chleba
Kod programu:
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
vector <string> wektor;
void zapisz(string filename)
{
fstream file( filename, ios::in );
string line;
int line_no = 0;
while( getline( file, line ) )
{
string cell;
stringstream line_stream( line );
int couter = 0;
while( getline( line_stream, cell, ' ') )
{
wektor.push_back(cell);
wektor.push_back(" ");
}
line_no++;
}
file.close();
}
int main()
{
zapisz("tekstowy.txt");
auto v=wektor.begin();
while(v!=wektor.end())
{
if (*v==" " && *(v-1)==" ")
{
v=wektor.erase(v);
}
else
v++;
}
for (auto w=wektor.begin(); w!=wektor.end(); ++w)
cout<<*w<<endl;;
system ("pause");
return 0;
}