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?