> Hi, I'm pretty new to c++ . I'm trying to work out why the following code
> doesn't work.
> I've just learned about cin.get() and written the following program to enter
> a string and store it in an array.
>
> When I run the program it asks for the first string and then prints it.
> However, it doesn't ask for input for the second string, it simply prints
> "Enter the second string", then "The second string is: ".
>
> Why doesn't cin.get() ask for input the second time around?
The problem is, because cin.get() reads characters from stdin until it
encounters a newline ('\n'). Then it finishes and writes a terminating 0 at
the end of the string. But the newline is pushed back to the input stream.

Then you run your second cin.get(). It starts reading characters from the
input stream and what does it notice first? The first character available
is '\n'! That means that we must stop and write the terminating 0!
That is the problem!
The simplest solution would be:
#include<iostream>
// #include<string> is not necessary here!
int main()
{
char bufferOne[50];
std::cout << "Enter the first string: ";
std::cin.get( bufferOne, 49 );
std::cout << "The first string is " << bufferOne << std::endl;
//OK, let's just read the remaining '\n'!
std::cin.get();
char bufferTwo[50];
std::cout << "Enter the second string: ";
std::cin.get( bufferTwo, 49 );
std::cout << "The second string is " << bufferTwo << std::endl;
return 0;
}
I know that there are other solutions also, but mine worked fine...
I hope it is useful for you.