-1

I am trying to limit the length of a line to fit on a page nicely and am using the following code

 if (!primes[j]) {
    stringstream st;
    st << j;
    test += " "+st.str();
    if (test.length() > 71) {
        cout << line << endl;
        line = st.str();
    } else {
        line += " "+st.str();
    }
    test = line;
}

I need to convert the int j to a string and add its chars to check if the line will become too long.

Anyways the problem is that my output is always:

12522
1548
78455

etc..

What is adding these lines?

Fireynis
  • 407
  • 6
  • 13

1 Answers1

1

flush there serves to signal end of the output and hence it adds the new line.

Peter G.
  • 7,816
  • 20
  • 80
  • 154
  • Ya this may have been my problem, thanks a bunch Also thanks to @NathanOliver for pointing it out too. Will accept this soon as I can. – Fireynis Oct 20 '15 at 16:42