How do I create a stringstream with a fixed length, filled with a single character?
Desired output:
[xxxxxxxxxx]
I've tried this:
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
stringstream ss;
ss << setfill('x') << setw(10);
cout << "[" << ss.str() << "]\n";
return 0;
}
output:
[]
If I add anything to the stream after I set the width and fill, I get filled stream, which is what I am looking for:
ss << setfill('x') << setw(10) << "B";
output:
[xxxxxxxxxB]
But I want a stream the stream to be filled with just x Is there any way to get the filled stream without needing to add a value to it?
Please login or Register to submit your answer