Aug 19, 2017 at 11:39am UTC
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?
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 Aug 19, 2017 at 12:12pm UTC
Aug 19, 2017 at 11:54am UTC
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 Aug 19, 2017 at 11:54am UTC
Aug 19, 2017 at 12:10pm UTC
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 Aug 19, 2017 at 12:33pm UTC
Aug 19, 2017 at 12:49pm UTC
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 Aug 19, 2017 at 1:33pm UTC