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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:23:07+00:00 2026-06-17T13:23:07+00:00

On os X 10.8, I tried to redirect std input to c++ string via

  • 0

On os X 10.8, I tried to redirect std input to c++ string via bash.

After I printed 1024th character, I even cannot press enter.

Could you please explain where the problem occurs and how to fix it?

  • 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-17T13:23:09+00:00Added an answer on June 17, 2026 at 1:23 pm

    The problem has nothing to do with bash, or with the C++ code. To verify this, this trivial program has the same problem:

    #include <iostream>
    #include <string>
    int main(int, char**) {
        std::string s;
        std::getline(std::cin, s);
    }
    

    And so does this Python program:

    #!/usr/bin/python
    raw_input()
    

    And you can try running under different shells and see that it makes no difference.

    The problem is that a TTY in line mode always has a max line length, and this one happens to have a max line length of 1024.

    So, this isn’t even really a programming question; it’s a TTY question. Which is why you can find a dup over at superuser.com instead of here. See the discussions there on the various ways to deal with this.

    However, if you want to deal with it from within your program, rather than globally, you can check whether stdin is a tty, and if so use termios functions to temporarily turn off line mode. For example, something like this:

    #include <iostream>
    #include <string>
    #include <termios.h>
    #include <unistd.h>
    
    int main(int, char**) {
      struct termios told;
    
      if (isatty(STDIN_FILENO)) {
        tcgetattr(STDIN_FILENO, &told);
        struct termios tnew = told;
        tnew.c_lflag &= ~ICANON;
        tcsetattr(STDIN_FILENO, TCSAFLUSH, &tnew);
      }
    
      std::string s;
      std::getline(std::cin, s);
    
      if (isatty(STDIN_FILENO)) {
        tcsetattr(STDIN_FILENO, TCSAFLUSH, &told);
      }
    }
    

    However, you’ll obviously want real error handling, and you’ll probably want to use RIAA to stash and restore the original termios settings, and you should probably read man termios to understand what you’re doing and what other effects it will have (and whether you want to do anything else).

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

Sidebar

Related Questions

I tried to redirect standart output (cout) to a file, for debugging purposes std::ofstream
I tried to redirect the users who directly enter the URL of the home
I tried to redirect the output of the time command, but I couldn't: $time
I tried: //301 Redirect Old File Redirect 301 www.mydomain.com/subdirectory http://newurl.com but that lands me
My .htaccess file in my htdocs folder does not work. I tried to redirect
i have tried this code to redirect a php page.but it s not working
I want to redirect back to referrer url in playframework and I have tried
how can i redirect index.php?search= to the base url? I tried it with this
Well, my website can not redirect to https://www.facebook.com/QuaFootSpa from http://quafootspa.com/ I have tried redirection
Tried searching the site, but cannot find an answer to my problem: Lets say

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.