You can't use >> to read something with spaces in it.
You can't use >> to read something with spaces in it.
Your current code is not using getline to read in the address. Any input that contains spaces should be read with getline. The suggestion to add the call to ignore() was not meant to replace the suggestion to use getline.
The call to cin.ignore() should be after all normal calls to cin >>. It is only technically needed between a call to cin >> and a call to getline, but because it can be hard to tell in some programs where exactly that happens, and because it is harmless to put cin.ignore() between calls to cin >>, the easiest correct solution is to always put cin.ignore() directly after a call to cin >> (but never directly after a call to getline).
i get an error:
the error is:Code:cout << "Address: "; cin.ignore(); cin.getline(theAddress); //cin >> theAddress;
Davidf:\c++2\addressClass\addressClass.cpp(115): error C2661: 'std::basic_istream<_Elem,_Traits>::getline' : no overloaded function takes 1 arguments
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
I believe what you want is std::getline, not cin.getline. The cin version takes an array of chars, IIRC, while the std::getline version takes an input stream and a string. It optionally takes a character delimiter (it defaults to newline).
You used getline correctly in your own code earlier in the thread. Use that code as an example of how to use it.
Got it working finally! YAY!
Thanks for the help!Code:cout << "Address: "; cin.ignore(); getline(std::cin, theAddress);
David