Looks complicated for a beginner. Thanks for the help though, my eyes have been opened :P
Few more questions ;)
How works that type-checking using cin.getline?
My compiler gives an error when i use cin.getline(input): he dont recognize that function with var-type string. You know wy?
Error:
12 C:\prog\test.cpp no matching function for call to `std::basic_istream<char, std::char_traits<char> >::getline(std::string&)'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <string>
using namespace std;
int main() {
char input[256] = {0};
cout << "Enter a sentence with spaces: \n>";
cin.getline(input, 256);
cout << "You entered: " << input << endl;
string input2 = "";
cout << "input another sentece with spaces: \n>";
cin >> input2;
cout << "This time you have: " << input2 << endl;
cout << "hmmm that's not right" << endl;
cout << "Done." << endl;
return 0;
}
|
Sorry, I often just write string instead of char[]. As they can often be used in place of each other :)
Last edited on
Oke, simply dont use strings :) I could have come up with that myself... Thanks anyway
Ps. Great link!
Last edited on
You will notice that cin >> input;
terminates after the space char and doesn't read anymore than 1 word. Another reason to use getline();