I'm trying to get my application to read in input with spaces. I already found out that I have to use the function getline().
However when I implement it in my code the application does not read in input at all at the place where the getline function is implemented. It just goes on with code execution as if the getline function wasn't there.
This is a part of my code:
...
float artprijs;
string artnaam;
text artnaam20;
cout << "Geef artikelprijs in: " << endl;
cin >> artprijs; // ingeven van de artikel prijs
cout << "Geef artikelnaam in: " ;
//cin >> artnaam;
//ingeven van de artikelnaam. 1000 karakters kunnen worden ingegeven
getline(cin, artnaam);
if (artnaam.length() > 19) //checken of de ingegeven artikelnaam groter is dan 19 karakters ja dan neen
{
for (int i = 0; i < 19 ; i++) // indien ja, kopieer de eerste 19 karakters naar artnaam20 en sluit af met de end-of-string karakter
{
artnaam20[i] = artnaam[i];
};
artnaam20[19] = '\0';
}
else
...
If somebody has already encountered this kind of error and could help me out, I would be very gratefull.