Answers for "what should i include when using getline in c++"

C++
0

getline in c++

#include<bits/stdc++.h>
using namespace std;
#define e  "\n"

int main()
{
    string food, name;
    int age;

    getline(cin,name);// for space
    cin>>age;
    cin.ignore();// to ignore the newline character
    getline(cin,food);
    cout<<name<<" "<<age<<" "<<food<<e;

    return 0;
}
Posted by: Guest on February-07-2022
4

getline cpp

//getline allows for multi word input including spaces ex. "Jim Barens"
#include <iostream>
#include <string>

int main() 
{
  string namePerson{};     // creating string
  getline(cin, namePerson);// using getline for user input
  std::cout << namePerson; // output string namePerson
}
Posted by: Guest on October-20-2020

Code answers related to "what should i include when using getline in c++"

Browse Popular Code Answers by Language