getting a specific character

Hi im trying to make a null cipher program and am trying to get some initial testing done. first im trying to see if i will be able to get the specific character i want while typing.

string c ;
c = cin.get() ;
while (!cin.eof()) // as long as ur typing
{
cout << c;
c = cin.get() ;
}

I have this so far to just print out whatever i type. But whenever i attempt to printout the second, third or whatever number letter of what i type it doesn't print out anything.
for example : cout << c[2]; or cout << c[3]; will give me blanks.
If i attempt to printout the first letter it just prints out the same thing i typed in.
i think it has something to do with the while loop. i feel like im missing something very simple... any input is appreciated!
cin.get() returns a single character from your current stream.

If you want to add to your buffer, try something like c += cin.get();
Typically, when you read from stdin which is the stream cin represents, you're not going to be looking for eof.

Why don't you just take a line at a time?
Topic archived. No new replies allowed.