1

Basically what I'm trying to do is to distribute spaces equally between words of a given string. This is what I did:

istringstream s("En el infinito y mas alla"); 
string token;
while( s >> token )
{
    cout << token << setw(10);
}

However, this is not working as expected. Anybody know why?

Borgleader
  • 15,826
  • 5
  • 46
  • 62
  • 1
    What exactly do you mean by "distribute spaces equally"? Do you want exactl 10 spaces between each word? Or are you trying to do something like justified alignment" in word processors? – Borgleader Mar 04 '14 at 02:29
  • 2
    setw sets the width of the output field, *including whatever you output*, so this won't insert 10 spaces between words. – melak47 Mar 04 '14 at 02:31
  • What michaeltang said was what I was looking for, however now that you mention about the justified alignment...How could I do that? – user3377176 Mar 04 '14 at 03:07

1 Answers1

2

may be this is what you want ?

 cout<< setw(10+token.size()) << token ;
michaeltang
  • 2,850
  • 15
  • 18