jonny b, try this out:
#include <iostream>
#include <string>
using namespace std;
void main()
{
double age;
string name;
cout << "how old are you?";
cin >> age;
cout << "what is your name?";
getline(cin, name);
getline(cin, name); //two needed to take in the \n character...
I ran across the same problem yesterday. Turns out that it's most likely due to putting #include <iostream.h> instead of just #include <iostream> (no .h). Try that and do post your code so I can make sure this is what you're referring to.
kenji, I was having the same issues. The solution thankfully is quite simple.
Change the iostream.h in the inclusion section to iostream :) getline(cin, string) will work after that. However, note: I have problems with this getline statement after importing numbers via cin anywhere else in the...
lemming, that is pretty good code, but is there any possible way to read the whole line in one go? For example:
What is your name?
Joe Shmo
and then you can assign Joe Shmo to the string. This is easily done in Java, and yet I find it nearly impossible in C++??? How can this be? I'm not even...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.