0
I’m learning to program in C++ and when I use the getline function(Cin,name) I can’t put text in there and the Avanca code for the next line. The program should ask for age and name and is supposed to have an output that indicates the age and name placed in the input. Can someone help me? Thank you
#include <iostream>
#include <string>
using namespace std;
int main()
{
int age;
cout << "Insere a tua idade: ";
cin >> age;
string nome;
cout << "Insere o teu nome: ";
getline(cin, nome);
cout << "Ola " << nome << "! Segundo a tua resposta tens: " << age << " anos" << endl;
return 0;
}
Thank you very much solved my problem!
– kikolaranjo
I think I ask something a bit stupid but what does "getline(Cin, name)" mean. How is that a condition?
– kikolaranjo
@kikolaranjo excuse the delay! Remember this: "no doubt is stupid". Basically it is pq C++ interprets while(0) AS FALSE and the other numerals and characters are interpreted as TRUE! This question will resolve your question: What is while(0) and while(1) in C?
– Luiz Augusto
If the answer helped you, Tour
– Luiz Augusto
Thanks again. It helped me a lot!
– kikolaranjo