I've recently came across this code in C++:
int main(){
std::string a='0'; //I missed the quotes here anyways that wasn't
//really necessary for the question
std::cout<<"Enter your number: ";
getline(std::cin,a);
int ia=std::stoi(a);
return 0;
}
So why would someone write code like that, when you can write it like this:
int main(){
int a=0;
cout<<"Enter a number: ";
cin>>a;
return 0;
}
(I'm using using namespace std;
by the way)
Why write longer code like in the first example? Is it more efficient considering time and memory?