Garmaine Staff asked 2 years ago

How do I create a stringstream with a fixed length, filled with a single character?

Desired output:


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;



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";



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?