c++ - Reading multiple lines from keyboard as input -


for code, had read multiple lines keyboard. code have here job. here code:

#include <iostream>  using namespace std;  int main() {  string input; string line;  cout<< "enter input line" << endl;  while (getline(cin, line)) {     if (line == "^d")         break;      input += line; }   cout<< "the input entered was: "<<endl;  cout<< input<< endl;  } 

the output after running this.

enter input line hello world ! input entered was:  helloworld ! 

the problem: see, getline give white space when printing hello world. how make sure gets printed "hello world !" rather "helloworld !" happens when there n newline. concatenated previous line string , printed.

try this,

while (getline(cin, line)) {     if (line == "^d")         break;      input += " " + line; } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -