getline vs cin.getline
getline(cin, variable_name, 'n');
getline vs cin.getline
getline(cin, variable_name, 'n');
what is the diffrence between getline and cin
$ cat ./getline_test.cpp
#include <string>
#include <iostream>
using namespace std;
int main() {
string s;
getline( cin, s, 'n' );
cout << s << endl;
}
$ g++ getline_test.cpp -o getline_test
$ ./getline_test
this is a test.
this is a test.
$ cat cin_test.cpp
#include <string>
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
cout << s << endl;
}
$ g++ cin_test.cpp -o cin_test
$ ./cin_test
this is a test.
this
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us