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 6378391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:59:57+00:00 2026-05-25T01:59:57+00:00

CODE: #include <iostream> #define BUFF 100 using namespace std; int main(int argc, char* argv[])

  • 0

CODE:

#include <iostream>

#define BUFF 100

using namespace std;

int main(int argc, char* argv[])
{
    char input[BUFF];

    cout << "Input:\n>";

    cin >> input;

    cout << "\n\nOutput:" << input;

    cin >> input;
    cin >> input;
}

How come when you read input into a char array it skips the spaces? oh and there is 2 cin’s(at the end) because it acts a little strange and exits if a space is entered when there is 1 cin…not sure why either.

EG

i enter cup cake and it outputs cup

  • 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-05-25T01:59:58+00:00Added an answer on May 25, 2026 at 1:59 am

    This is basically because operator>> for std::cin takes one “input object” between whitespaces (i.e. , \t, \n) and reads it into given variable/object. Try:

    std::string input[2];
    std::cout << "Input:\n>";
    std::cin >> input[0] >> input[1];
    

    For input cup cake you will get input[0] == "cup" and input[1] == "cake".

    If you don’t read whole input it stays in the input buffer; that is why you need two cin >> input at the end of main(), which made you confused. The explanation is that you read "cup" into input, but "cake" stays in buffer ready for next read.

    This behaviour is very handy when reading into several variables, e.g.:

    int a, b, c;
    std::cin >> a >> b >> c;
    

    This allows you to write three integers separated by whitespace and they’ll get read into proper variables. If you need whole line of input, try as suggested by David Rodríguez and use std::getline.

    EDIT Actually, after reading std::cin >> input[0] >> input[1] the input buffer will still not be empty since it contains an \n character (after pressing ENTER). To empty input buffer try:

    std::cin.clear(); // optional, use when input has gone bad; clears error flags
    std::cin.sync(); // empty buffer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
Code: #include <iostream> using namespace std; #define ADD(x,y) ((x)+(y)) int main( int argc, char**
The following code #include <iostream> using namespace std; int main() { const char* const
Consider the following code: #include <iostream> using namespace std; int main() { int x,
I have this code main.cpp #include <iostream> #include functs.h using namespace std; int main()
With this code: #include <iostream> int main(int argc, char *argv[]) { return 0; }
following code for partition #include<iostream> using namespace std; #define maxn 10000 int x[maxn]; void
This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout
I've try to compile this code: #include <iostream> #include <cstdlib> using namespace std; #define
Consider the following code: #include <iostream> #include <memory> #include <vector> using namespace std; struct

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.