Answers for "getline"

C++
12

get line 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;
}
Posted by: Guest on November-16-2019
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
1

getline()

SensorsFile::SensorsFile(const string fname, bool verbose)    
  : Sensors(fname, verbose){  
  
  // BEGIN: F2  
 
  ifstream inFile(fname);  
  if (!inFile) {    
    throw runtime_error("Could not read from file " + fname + '\n');  
  }  
  
  string line;  
  // auto dummy;
  
  unsigned int timestep;  
  string dam;  int inflow;  
  int outflow;  
  getline(inFile, line); // Denne for å fjerne første linje av filen!  
  
  // Her er det viktig å huske at vi må fjerne første linje, da denne kun er til info.  
  while (getline (inFile, line)) {    
    // stringstream ss;    
    string dummy; 
    
    getline(inFile, dummy, ',');    
    timestep = stoi(dummy);    
    
    getline(inFile, dummy, ',');    
    dam = dummy;    
    
    getline(inFile, dummy, ',');   
    inflow = stoi(dummy);    
    
    getline(inFile, dummy, ',');    
    outflow = stoi(dummy);    
    
    insert_reading(timestep, dam, inflow, outflow);  
  } 
  
  inFile.close();  
  
  // END: F2
  }
Posted by: Guest on July-28-2021
0

getline

istream& getline (istream& is, string& str);
Posted by: Guest on June-04-2021

Browse Popular Code Answers by Language