Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:40:10+00:00 2026-06-09T04:40:10+00:00

I have for example the following piece of code: string str; int i; cout<<input:;

  • 0

I have for example the following piece of code:

string str;
int i;
cout<<"input:";
cin>>str;
cout<<"integer:";
cin>>i;

There is actually nothing wrong with this code, but if I paste some text into the command prompt in “input”, it automatically fills some of the copied text into “integer”. How can I solve this?

Edit: I can type texts as long as I want, but when I copy texts it goes wrong. I don’t know why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:40:11+00:00Added an answer on June 9, 2026 at 4:40 am

    I guess, your text contains white spaces. So, std::cin will not work here. Use std::getline instead.

    std::string str;
    std::getline( std::cin, str );
    

    There’s a third parameter of std::getline – delimiter. By default, it’s the new line char.


    If your text does contain new line chars, than this will not work. You have 2 options:

    • find unique char, that may be used as delimiter and pass it as third parameter of std::getline
    • read line by line (using std::getline) from the user input (std::cin) and look for some special string, that will tell your program where the text ends. There’s no other way to know where does the integer start (unless the text is with fixed size, but I doubt that)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of code - jsfiddle example The problem i'm having
I have the following piece of code (shortened for the example): while (reader.ready()) {
I have the following piece of code, as an example dec_proxy attempts to reverse
I have the following example code: $dataProvider = new CActiveDataProvider('firstTable', array('criteria' => array( 'select'
I have the following example, compiled in VS2005, warning level 4: int main(int argc,
I have the following piece of code: try{ SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp
I have this piece of code (from the Nokia PC connectivity 3.2 example code,
I have the following piece of code which replaces template markers such as %POST_TITLE%
I have the following piece of code that will give me the date 1
Here's what I want to do. I have the following piece of code: Private

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.