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

This is a discussion on What's the difference between cin >> and cin.get()? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by whiteflags I still recommend std::string. I will echo that. There is no sense in using C-style strings....

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,777
    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
    122
    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 05:59 PM. Reason: added last line

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,777
    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
    122
    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 04:34 PM. Reason: added quote

Page 2 of 2 FirstFirst 12
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

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