How to replace line read from file

I am trying to change the line when there is no chars in it.

I tried this:
line = line + "<h3>" + cStr.str() + "<h3>";

but it breaks the program during debugging. What is the problem?

 
std::stringstream cStr;


1
2
3
4
5
6
7
8
9
10
          while ( ifs.good() )
             {
             getline (ifs, line);
             if ( line.length() == 0) {
                 c++;
                 cStr << c;
                 line = line + "<h3>"  + cStr.str() + "<h3>";
                 }

             std::cout << line << std::endl;
Last edited on
1
2
3
4
5
6
7
8
9
while( getline( ifs, line ) ) // canonical way to write the loop
{
     if( line.empty() ) 
     {
         c++ ;
         line = "<h3>"  + std::to_string(c) + "<h3>";
     }
     std::cout << line << '\n' ;
}
Last edited on
I have tried the method you used already and it did this error:
'to_string' is not a member of 'std'|

Now I read it is bug fixed in MinGW 4.9.2 (64 bit). I am running 32 bit Windows...
Last edited on
I solved it like this:

1
2
3
4
5
6
7
8
getline (ifs, line);
if ( line.length() == 0) {
                 c++;
                 sprintf(iStr, "%d", c);
                 line += "<h3>";
                 line += iStr;
                 line += "</h3>";
}


Thank you
Last edited on
Topic archived. No new replies allowed.