Odd msdos console behavior.

This is a discussion on Odd msdos console behavior. within the C++ Programming forums, part of the General Programming Boards category; Ok, using gcc 3.2 I have some strange behavior when the user enters ^Z(26) as the dos eof marker. It ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    311

    Odd msdos console behavior.

    Ok, using gcc 3.2 I have some strange behavior when the user enters ^Z(26) as the dos eof marker. It seems that standard output wants to eat a line for no reason. This only happens when both cin and cout are directed to the console. This is using the command.com from windows 98 (under 98) Example:
    Code:
    #include<iostream>
    #include<string>
    int main(int argc, char *argv[]) {
        std::string line;
        char ch;
        while(std::cin.get(ch)) line += ch;
        std::cout << "Begin echo:" << std::endl; // this line will be eaten
        std::cout << '(' << line << ')' << std::endl;
       
        return 0;
    }
    In this case "Begin echo:" is never seen. If that line is removed then stdout eats the first line in the string 'line'. In other words everything up to the first \n is ignored, regardless of source. Agressive flushing of buffers does not help.

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    redirection works as expected(correctly), I think you are on to something with the excessive \r cout << char(10) before the first line "Begin Echo" seems to make everything work, it's just the linefeed that is eaten ( no blank/stairstep is produced though). On the other hand "very long\rnot " produces "not long" while a short line does not leave any part of begin echo on the screen. strange.

    I am using the mingw build of gcc, though not from Dev-C++.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I think it might have to do with you dealing of eof. Try using this loop instead:

    Code:
    while(!std::cin.eof())
    {     std::cin.get(ch);
          line+=ch;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Odd harddrive behavior.
    By psychopath in forum Tech Board
    Replies: 6
    Last Post: 04-13-2007, 05:58 PM
  2. odd MSVC link.exe behavior
    By skorman00 in forum Tech Board
    Replies: 2
    Last Post: 09-11-2006, 12:25 PM
  3. Odd resizing behavior in MFC
    By VirtualAce in forum Windows Programming
    Replies: 6
    Last Post: 01-10-2006, 07:31 PM
  4. Overriding default behavior in DOS console w/MFC
    By Waldo2k2 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-10-2002, 08:42 AM
  5. odd behavior of cin.getline when it follows cin
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 01-28-2002, 01:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21