cout noob question
Hey guys :D
Would be possible to append the cout data into a string object?
Like this code for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main () {
string s;
for (int i = 1; i <= 10; i++) {
cout << setfill ('0') << setw (2) << i << "\n";
//s.append(cout.( ??? ))
}
cout << endl << s.data();
cin.get();
return 0;
}
|
If not possible, how would be the proper way to insert these 2 digit numbers into the string?
Thanks,
1 2 3 4 5
|
stringstream ss;
for (int i = 1; i <= 10; i++) {
ss << setfill ('0') << setw (2) << i << "\n";
}
cout << endl << ss.str();
|
ahhh.. stringstream :D
Thanks a lot Athar, perfect!
Topic archived. No new replies allowed.