“Obter linha” Respostas de código

Obtenha a linha c

// extract to string
#include <iostream>
#include <string>

int main ()
{
  std::string name;

  std::cout << "Please, enter your full name: ";
  std::getline (std::cin,name);
  std::cout << "Hello, " << name << "!\n";

  return 0;
}
Collared Lemming

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
}
breeze

Obter linha

#include <bits/stdc++.h>
using namespace std;

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
int t;
string a,b;
cin>>a;
cin.ignore();  /*must include this otherwise the cin will 
have null space availabe in buffer and getline wont take 
anything as input so we must clear or ignore the space 
availabe in buffer due to previous input */
getline(cin,b);

cout<<a<<b;
}
Siddhant Jha

Obter linha

Make sure you didn't use cin >> str. before calling the function. If you use cin >> str and then want to use getline(cin, str), you must call cin.ignore() before.

string str;
cin >> str;
cin.ignore(); // ignores \n that cin >> str has lefted (if user pressed enter key)
getline(cin, str);
Siddhant Jha

Respostas semelhantes a “Obter linha”

Perguntas semelhantes a “Obter linha”

Procure respostas de código populares por idioma

Procurar outros idiomas de código