I wanted to store space separated strings with cin
, and I learned that I have tot use getline
. But if there is another cin
before getline cin
, second cin
is not read.
Here is example:
using namespace std;
int main() {
int ID;
string Artist;
cout << "Enter ID:\n";
cin >> ID;
cout << ID << " this is ID\n";
cout << "Enter Artist name:\n";
std::getline(cin, Artist);
cout << Artist << " this is Artist\n";
system("pause");
return 0;
}
Artist is not prompted for entry, and assigned "". How to fix that?