How to read string character by character?

I have a problem where I need to take a string input by the user and convert it into a series of words used to spell it out phonetically. For example:

Enter sting: program
Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike.

I can do the converting process, but I have no idea how to take the string and read it character by character. Keep in mind I'm in my first C++ class ever and don't know much, so try and keep it simple.

Any help is greatly appreciated ;)
You could loop through it like an array:
1
2
3
4
for(unsigned Pos = 0; Pos < Input.length(); ++Pos)
{
     //Address each element like this "Input[Pos]"
}
I don't think I've learned about array's yet, I really don't know what that is.

I found a function mentioned in my book called the "at" function, could I do something like this:


1
2
3
4
5
6
while (currentChar != '\n')
	{
		currentChar = userInput.at(pos);
		CharConvert(currentChar);               //CharConvert is the function that will handle the conversion 
		pos++;
	}


Where userInput is the string, and pos is the position char.
Last edited on
Well it seems to have worked, having other unrelated (I think) problems now, but I think that worked.
Topic archived. No new replies allowed.