“Getline CPP” Kode Jawaban

Dapatkan baris 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 di 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;
}
pra's play

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

Jawaban yang mirip dengan “Getline CPP”

Pertanyaan yang mirip dengan “Getline CPP”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya