hello all. I'm relatively new here. and very much a newbie in c++, string manipulation. I couldn't solve this. it has taken me soooo long. I did search the entire forum and google but those solutions seem a bit advance for my string problem. I know this is just basic, so all of you are welcome to help :)

I ask a user to input {2 + (3-6) * 8} as a string.
then I want every each of the string in array :
ar[0] = {
ar[1] = 2
ar[2] = +
ar[3] = (
and so on until }

how do I implement this in c++?

what about a user input "My Name is Marianne" as a string.
then every each of the string in array of words :
ar[0] = My
ar[1] = Name
ar[2] = is
and so on until Marianne.

## All 9 Replies

I ask a user to input {2 + (3-6) * 8} as a string.
then I want every each of the string in array :
ar[0] = {
ar[1] = 2
ar[2] = +
ar[3] = (
and so on until }

how do I implement this in c++?

Every each? Each is not a noun. You mean every character.

Just input it into a string. By definition `ar[0]` will be the first character. That's true for strings and char *s.

what about a user input "My Name is Marianne" as a string.
then every each of the string in array of words :
ar[0] = My
ar[1] = Name
ar[2] = is
and so on until Marianne.

word, not each.

Make an array of strings and place each word into each element.

ya, I have a terrible headache. I don't quite comprehend each, character, words and alike right now at this time everything is a messed in the head.
ok just how exactly you do this? could you please give the coding and a bit explanation along the way?I understand the logic but not the coding

I don't quite comprehend each, character, words and alike...

You're kidding, right?
For each, words, and alike, check a dictionary.
For character, check your class text.

Why not import math* and solve the equation as a complete string why do you need an array except to take up space. string strProblem= keyboard input: Anything between " and " will be considered the string.You don't have to break it down unless it is a classroom thing.

An example:

``````std::string expression = " (2*3) + 8/9";
//expression[0] = '(';
//expression[1] = '2';
//expression[2] = '*'
//...and so on``````

An example:

``````std::string expression = " (2*3) + 8/9";
//expression[0] = '(';
//expression[1] = '2';
//expression[2] = '*'
//...and so on``````

no no. what i mean is, user input a string of "{2+ (3-6) * 8}".
I want each char to be in array.

for example :

string str;
cout<<"Entered arithmetic"<<endl;
cin.getline(str);

I want each char in str to be in array. just how to do this?

second problem

string str2;
cout<<"Enter sentences"<<endl;
cin.getline(str2);

I want each words in str2 to be in array . "hi" in ar[0]. "my" in ar[1] "name" in ar[2] ..

Why not import math* and solve the equation as a complete string why do you need an array except to take up space. string strProblem= keyboard input: Anything between " and " will be considered the string.You don't have to break it down unless it is a classroom thing.

this is my project. I forgot a lot about string manipulation.
i want {2 + (3-4) * 8} be in string type. so I could do stack operation. no math involve just to find matching grouping symbols