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

  • SEARCH
  • Home
  • 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 8858071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:44:36+00:00 2026-06-14T14:44:36+00:00

Why does the same program giving different outputs when inputs are given through different

  • 0

Why does the same program giving different outputs when inputs are given through different methods?

Program 1:

int main(){
    char s[10];
    cout << "Enter a String\n";
    cin >> s;
    cout << "The entered String is\n";
    cout << s << "\n";
    return 0;
}  

When I give input through command line “Hello World”, the output I’m getting is only “Hello”

Program 2:

int main(){
    char s[] = "Hello World";
    cout << "The entered String is\n";
    cout << s << "\n";
    return 0;
}  

In this case, I’m getting output of “Hello World”.

What is the difference between both programs? Is the logic the same? How can I obtain the whole string “Hello World” when entered through the command line? Is there a way?

  • 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-14T14:44:38+00:00Added an answer on June 14, 2026 at 2:44 pm

    Use getline():

    string s;
    getline(cin, s);
    cout << "The entered String is\n";
    cout << s << "\n";
    

    The problem with your code is that the input stream extraction operator >> only gets characters up to the next whitespace (so, just one “word”). The getline() function gets the whole line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does any body know how to set different select statement for the same cursor?
How does the .NET CLR handle multiple instances of the same program running simultaneously?
I have a C program giving different results when run on two machines. On
How does the Same Origin Policy apply to the following two domains? http://server1.MyDomain.com http://server2.MyDomain.com
Is there a C function that does the same as raw_input in Python? #in
Could one help translating following sed command so it does the same on aix
I'm working on an algorithm that does prettymuch the same operation a bunch of
Does this function has the same behavior that memset ? inline void SetZeroArray( void
Does anybody know why the same code from this page http://emacsformacosx.com/ would not render
Does anyone have the same problem as I do? ... I've upgraded to the

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.