How to read all of the text on a line starting on that line?2019 Community Moderator ElectionHow do you set, clear, and toggle a single bit?How do I iterate over the words of a string?How can I profile C++ code running on Linux?How to remove border (outline) around text/input boxes? (Chrome)Read file line by line using ifstream in C++Why is reading lines from stdin much slower in C++ than Python?How do I get the value of text input field using JavaScript?Basic String inputC++ multiple line input from keyboardmixing cin and getline input issues
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
How to change two letters closest to a string and one letter immediately after a string using notepad++
Brexit - No Deal Rejection
Recruiter wants very extensive technical details about all of my previous work
Min function accepting varying number of arguments in C++17
What options are left, if Britain cannot decide?
It's a yearly task, alright
Is there a data structure that only stores hash codes and not the actual objects?
Can I use USB data pins as power source
How Could an Airship Be Repaired Mid-Flight
how to write formula in word in latex
Is it normal that my co-workers at a fitness company criticize my food choices?
Why did it take so long to abandon sail after steamships were demonstrated?
How to read the value of this capacitor?
Why is the President allowed to veto a cancellation of emergency powers?
Happy pi day, everyone!
Why do Australian milk farmers need to protest supermarkets' milk price?
What are substitutions for coconut in curry?
How to terminate ping <dest> &
Interplanetary conflict, some disease destroys the ability to understand or appreciate music
Define, (actually define) the "stability" and "energy" of a compound
Professor being mistaken for a grad student
Life insurance that covers only simultaneous/dual deaths
What do Xenomorphs eat in the Alien series?
How to read all of the text on a line starting on that line?
2019 Community Moderator ElectionHow do you set, clear, and toggle a single bit?How do I iterate over the words of a string?How can I profile C++ code running on Linux?How to remove border (outline) around text/input boxes? (Chrome)Read file line by line using ifstream in C++Why is reading lines from stdin much slower in C++ than Python?How do I get the value of text input field using JavaScript?Basic String inputC++ multiple line input from keyboardmixing cin and getline input issues
I am trying to read someone's full name in C++, and obviously that would have spaces (like "John Doe"). The easiest way I can do this (since cin
by default breaks at whitespace) is with getline(cin, str)
where "str" is the variable.
However, when doing this, it starts reading text on the next line. Instead of this:
Please enter your full name > John Doe
You get
Please enter your full name >
John Doe
Here's the code that produces the result:
string fullName;
cout << "Please enter your full name >";
getline(cin, fullName);
Is there any way I can read the full line and still keep it on the same line?
c++ input
|
show 2 more comments
I am trying to read someone's full name in C++, and obviously that would have spaces (like "John Doe"). The easiest way I can do this (since cin
by default breaks at whitespace) is with getline(cin, str)
where "str" is the variable.
However, when doing this, it starts reading text on the next line. Instead of this:
Please enter your full name > John Doe
You get
Please enter your full name >
John Doe
Here's the code that produces the result:
string fullName;
cout << "Please enter your full name >";
getline(cin, fullName);
Is there any way I can read the full line and still keep it on the same line?
c++ input
2
The trick is to avoid emitting the linefeed when printing the prompt. It has nothing to do with the getline call. Please show your code that makes the prompt.
– L. Scott Johnson
Mar 6 at 19:58
Can you show the code that causes that effect? I am not sure what you are saying.
– Galik
Mar 6 at 19:59
1
"However, when doing this, it starts reading text on the next line." Makes little sense. Please provide Minimal, Complete, and Verifiable example, that illustrates the problem.
– Algirdas Preidžius
Mar 6 at 19:59
Unless you press return before typing in a name I don't see anything in that code that will move what you type onto the next line. I am still not sure what is supposed to be happening here tbh.
– Galik
Mar 6 at 20:03
Given the code sample, I fail to reproduce the output you claim to be receiving. Are you certain, that this is the code, that you are trying to reproduce the issue with?
– Algirdas Preidžius
Mar 6 at 20:07
|
show 2 more comments
I am trying to read someone's full name in C++, and obviously that would have spaces (like "John Doe"). The easiest way I can do this (since cin
by default breaks at whitespace) is with getline(cin, str)
where "str" is the variable.
However, when doing this, it starts reading text on the next line. Instead of this:
Please enter your full name > John Doe
You get
Please enter your full name >
John Doe
Here's the code that produces the result:
string fullName;
cout << "Please enter your full name >";
getline(cin, fullName);
Is there any way I can read the full line and still keep it on the same line?
c++ input
I am trying to read someone's full name in C++, and obviously that would have spaces (like "John Doe"). The easiest way I can do this (since cin
by default breaks at whitespace) is with getline(cin, str)
where "str" is the variable.
However, when doing this, it starts reading text on the next line. Instead of this:
Please enter your full name > John Doe
You get
Please enter your full name >
John Doe
Here's the code that produces the result:
string fullName;
cout << "Please enter your full name >";
getline(cin, fullName);
Is there any way I can read the full line and still keep it on the same line?
c++ input
c++ input
edited Mar 6 at 20:00
Luther
asked Mar 6 at 19:55
LutherLuther
11
11
2
The trick is to avoid emitting the linefeed when printing the prompt. It has nothing to do with the getline call. Please show your code that makes the prompt.
– L. Scott Johnson
Mar 6 at 19:58
Can you show the code that causes that effect? I am not sure what you are saying.
– Galik
Mar 6 at 19:59
1
"However, when doing this, it starts reading text on the next line." Makes little sense. Please provide Minimal, Complete, and Verifiable example, that illustrates the problem.
– Algirdas Preidžius
Mar 6 at 19:59
Unless you press return before typing in a name I don't see anything in that code that will move what you type onto the next line. I am still not sure what is supposed to be happening here tbh.
– Galik
Mar 6 at 20:03
Given the code sample, I fail to reproduce the output you claim to be receiving. Are you certain, that this is the code, that you are trying to reproduce the issue with?
– Algirdas Preidžius
Mar 6 at 20:07
|
show 2 more comments
2
The trick is to avoid emitting the linefeed when printing the prompt. It has nothing to do with the getline call. Please show your code that makes the prompt.
– L. Scott Johnson
Mar 6 at 19:58
Can you show the code that causes that effect? I am not sure what you are saying.
– Galik
Mar 6 at 19:59
1
"However, when doing this, it starts reading text on the next line." Makes little sense. Please provide Minimal, Complete, and Verifiable example, that illustrates the problem.
– Algirdas Preidžius
Mar 6 at 19:59
Unless you press return before typing in a name I don't see anything in that code that will move what you type onto the next line. I am still not sure what is supposed to be happening here tbh.
– Galik
Mar 6 at 20:03
Given the code sample, I fail to reproduce the output you claim to be receiving. Are you certain, that this is the code, that you are trying to reproduce the issue with?
– Algirdas Preidžius
Mar 6 at 20:07
2
2
The trick is to avoid emitting the linefeed when printing the prompt. It has nothing to do with the getline call. Please show your code that makes the prompt.
– L. Scott Johnson
Mar 6 at 19:58
The trick is to avoid emitting the linefeed when printing the prompt. It has nothing to do with the getline call. Please show your code that makes the prompt.
– L. Scott Johnson
Mar 6 at 19:58
Can you show the code that causes that effect? I am not sure what you are saying.
– Galik
Mar 6 at 19:59
Can you show the code that causes that effect? I am not sure what you are saying.
– Galik
Mar 6 at 19:59
1
1
"However, when doing this, it starts reading text on the next line." Makes little sense. Please provide Minimal, Complete, and Verifiable example, that illustrates the problem.
– Algirdas Preidžius
Mar 6 at 19:59
"However, when doing this, it starts reading text on the next line." Makes little sense. Please provide Minimal, Complete, and Verifiable example, that illustrates the problem.
– Algirdas Preidžius
Mar 6 at 19:59
Unless you press return before typing in a name I don't see anything in that code that will move what you type onto the next line. I am still not sure what is supposed to be happening here tbh.
– Galik
Mar 6 at 20:03
Unless you press return before typing in a name I don't see anything in that code that will move what you type onto the next line. I am still not sure what is supposed to be happening here tbh.
– Galik
Mar 6 at 20:03
Given the code sample, I fail to reproduce the output you claim to be receiving. Are you certain, that this is the code, that you are trying to reproduce the issue with?
– Algirdas Preidžius
Mar 6 at 20:07
Given the code sample, I fail to reproduce the output you claim to be receiving. Are you certain, that this is the code, that you are trying to reproduce the issue with?
– Algirdas Preidžius
Mar 6 at 20:07
|
show 2 more comments
1 Answer
1
active
oldest
votes
Without a Minimal, Complete, Verifiable Example, it is difficult to diagnose the issue you're having. However, I am able to produce code that reads a line of input from the user without breaking the previous "Enter your name>" line:
#include <iostream>
#include <string>
int main()
std::string str;
std::cout << "Please enter your full name > ";
std::getline(std::cin, str);
std::cout << "Hello " << str << std::endl;
return 0;
If you've gotten into the habit of appending all std::cout
lines with std::endl
, you may have neglected to omit it that time.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031228%2fhow-to-read-all-of-the-text-on-a-line-starting-on-that-line%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Without a Minimal, Complete, Verifiable Example, it is difficult to diagnose the issue you're having. However, I am able to produce code that reads a line of input from the user without breaking the previous "Enter your name>" line:
#include <iostream>
#include <string>
int main()
std::string str;
std::cout << "Please enter your full name > ";
std::getline(std::cin, str);
std::cout << "Hello " << str << std::endl;
return 0;
If you've gotten into the habit of appending all std::cout
lines with std::endl
, you may have neglected to omit it that time.
add a comment |
Without a Minimal, Complete, Verifiable Example, it is difficult to diagnose the issue you're having. However, I am able to produce code that reads a line of input from the user without breaking the previous "Enter your name>" line:
#include <iostream>
#include <string>
int main()
std::string str;
std::cout << "Please enter your full name > ";
std::getline(std::cin, str);
std::cout << "Hello " << str << std::endl;
return 0;
If you've gotten into the habit of appending all std::cout
lines with std::endl
, you may have neglected to omit it that time.
add a comment |
Without a Minimal, Complete, Verifiable Example, it is difficult to diagnose the issue you're having. However, I am able to produce code that reads a line of input from the user without breaking the previous "Enter your name>" line:
#include <iostream>
#include <string>
int main()
std::string str;
std::cout << "Please enter your full name > ";
std::getline(std::cin, str);
std::cout << "Hello " << str << std::endl;
return 0;
If you've gotten into the habit of appending all std::cout
lines with std::endl
, you may have neglected to omit it that time.
Without a Minimal, Complete, Verifiable Example, it is difficult to diagnose the issue you're having. However, I am able to produce code that reads a line of input from the user without breaking the previous "Enter your name>" line:
#include <iostream>
#include <string>
int main()
std::string str;
std::cout << "Please enter your full name > ";
std::getline(std::cin, str);
std::cout << "Hello " << str << std::endl;
return 0;
If you've gotten into the habit of appending all std::cout
lines with std::endl
, you may have neglected to omit it that time.
answered Mar 6 at 20:00
Govind ParmarGovind Parmar
12.9k53763
12.9k53763
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031228%2fhow-to-read-all-of-the-text-on-a-line-starting-on-that-line%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
The trick is to avoid emitting the linefeed when printing the prompt. It has nothing to do with the getline call. Please show your code that makes the prompt.
– L. Scott Johnson
Mar 6 at 19:58
Can you show the code that causes that effect? I am not sure what you are saying.
– Galik
Mar 6 at 19:59
1
"However, when doing this, it starts reading text on the next line." Makes little sense. Please provide Minimal, Complete, and Verifiable example, that illustrates the problem.
– Algirdas Preidžius
Mar 6 at 19:59
Unless you press return before typing in a name I don't see anything in that code that will move what you type onto the next line. I am still not sure what is supposed to be happening here tbh.
– Galik
Mar 6 at 20:03
Given the code sample, I fail to reproduce the output you claim to be receiving. Are you certain, that this is the code, that you are trying to reproduce the issue with?
– Algirdas Preidžius
Mar 6 at 20:07