Thread: What's the difference between cin >> and cin.get()?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by whiteflags View Post
    I still recommend std::string.
    I will echo that. There is no sense in using C-style strings.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    132
    All right I get it now. Aren't I right that the null character is never printed?
    Code:
    cout << '\0' << endl;
    Nothing gets printed.
    Wait a minute - the null character gets printed the same as a space.
    Last edited by c_weed; 11-26-2010 at 06:59 PM. Reason: added last line

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by c_weed View Post
    All right I get it now. Aren't I right that the null character is never printed?
    Code:
    cout << '\0' << endl;
    Nothing gets printed.
    That is correct.

    Wait a minute - the null character gets printed the same as a space.
    No, it doesn't. Do you have empirical proof of this?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    132
    Quote Originally Posted by Elysia View Post
    Do you have empirical proof of this?
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        cout << "hello" << endl;//flush to the right side
        cout << '\0' << "hello" << endl;//space before hello
    
        return 0;
    }
    Last edited by c_weed; 11-29-2010 at 05:34 PM. Reason: added quote

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin.get() Troubles
    By yukapuka in forum C++ Programming
    Replies: 19
    Last Post: 06-04-2008, 01:30 PM
  2. Istream cin vs. cin.get
    By Mehdi in forum C++ Programming
    Replies: 11
    Last Post: 08-31-2006, 11:26 AM
  3. cin.get() problem
    By Cilius in forum C++ Programming
    Replies: 20
    Last Post: 07-28-2005, 05:32 PM
  4. Confused about cin.get(); and classes.
    By RaccoonKing in forum C++ Programming
    Replies: 6
    Last Post: 07-17-2005, 11:44 AM
  5. cin.get();
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2005, 07:51 AM