Wednesday, 18 September 2013

How can I separate user inputted string and store it into an array

How can I separate user inputted string and store it into an array

I was wondering if you could help me and figure this out without using
something like strtok. This assignment is meant for me to build something
that will accept input and direct the user to the right area. I want to
get something like....
Help Copy
and it stores it as
array[1] = Help
array[2] = Copy.
I tried to do something like cin>>arr[1]; and cin>>arr[2] but at the same
time what if the user enters copy then I am not sure how to do it cause if
I put just one cin then what if the user puts help copy.
Basically I am not sure how to accept any size input and store anything
they put in as elements in an array.
I would try something like cin.get or getline but they don't seem to
really help me and my cin idea was not helpful at all.
This is what I have so far.
int main()
{
string user;
cout<<"Hello there, what is your desired username?"<<endl;
cin >> user;
system("cls");
cout<<"Hello, " << user << "! How are you doing?"<<endl<<endl;
cout<< user << ": ";
return 0;
}

No comments:

Post a Comment