How do I set this up to only read the first word the user enters IF they enter to much info?
I do not want to use an if-else statement demanding they enter new info because their info was to much.
I just want it to basically ignore everything after the first word and only print the first word entered. Is this even possible?
const int SIZEB = 10;
char word[SIZEB];
cout << " Provide a word, up to 10 characters, no spaces. > " << endl;
cin.getline(word, SIZEB);
cout << " The word is: " << word << endl;
cout << endl;
UPDATE
It HAS to be a cstring. This is something I am working on for school. I am asking a series of questions and storing the answers as cstring in the first round. Then there is a second round where I store them as string.
std::string
instead of char arrays -- otherwise use C. Don't use C++ like it was C. – Lim\0
after the word. – Subsistentstd::isalpha
. – Subsistentusing namespace std;
then you can simply refer to thestd::string
type asstring
. There is still absolutely no reason to be using C-style strings. Having said that, if your teacher/professor is teaching the use ofusing namespace std;
and is also requiring that you use C-style strings, it's quite clear that your professor has no ****ing idea how to teach C++. If it is within your means do to so, I would look for another teacher. – Lim