stdin to string array

How would I take a single string and assign it to a string array?

Example

cout << "enter a string";
cin >> teststring;

//my input "Hello World"
//and then in the array a[0]= Hello and a[1] = world


You would first have to create a string variable and an array. Have you tried doing this yourself? I see no code here
yeah I've been tooling around and I was able to get it to work somewhat but using loops with a defined end. I just want it to be I enter a single string. so in my code I entered "hello how are you" and it parsed the four words into command[0-3] and prompted me to enter the next 6 lines.

main()
{
string command[50];

cout << "enter string: ";
for(int i=0; i<10 ; i++)
{
cin >> command[i];
}
for(int i=0; i<10; i++)
{
cout<<command[i]<< endl;
}
return 0;
}
Try entering a single string, then have your loops only display a certain amount of characters. Think of your string as an array of characters. In the end, that is exactly what a string is; an array of characters under a named data-type.
Topic archived. No new replies allowed.