Answers for "difference between getline and cin"

C++
0

getline vs cin.getline

getline(cin, variable_name, 'n');
Posted by: Guest on August-11-2020
0

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
Posted by: Guest on November-03-2020

Code answers related to "difference between getline and cin"

Browse Popular Code Answers by Language