I'm wondering why it prints so many spaces when I only ask it to print one. Here's the code:

#include <iostream>
#include <string>
using namespace std;
string ar[21] = "                    ";
int main()
     ar[3] = "M";
     ar[4] = "n";
     for(unsigned int i=0 ; i<20 ; i++)
          cout << ar[i] << ", ";

Er, you're confusing strings with char arrays me thinks.

You are creating an array of strings in which each 'cell' would contain a string and initializing those strings to contain 20 characters. (approx). You either need to do

string ar[21] = " ";
string ar = "                    ";

And btw, you loop is off by one. You need to loop from 0 to 20 and not 0 to 19.

Well yes, a better way, rather than to count how many characters are in your string is to call the .length() function.

> Thanks people, I'm learning here.
Heh, welcome.