Thread: Problems with skipws

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    6

    Problems with skipws

    The program :
    ================
    Code:
    #include <iostream>
    using namespace std;
    
    int main () {
      int n;
      cin >> skipws >> n;
      cout << n << endl;
      return 0;
    }
    ================

    upon compilation throws up the following errors:

    ====================================
    # g++ skipws.cpp
    skipws.cpp: In function `int main()':
    skipws.cpp:6: `skipws' undeclared (first use this function)
    skipws.cpp:6: (Each undeclared identifier is reported only once
    skipws.cpp:6: for each function it appears in.)

    ====================================

    upon modification to:
    =========================
    Code:
    #include <iostream>
    using namespace std;
    
    int main () {
      int n;
      cin >> ios::skipws >> n;
      cout << n << endl;
      return 0;
    }
    =========================

    It now throws up the error:
    ====================================
    # g++ skipws.cpp
    skipws.cpp: In function `int main()':
    skipws.cpp:6: initializing non-const `int &' with `ios::{anonymous enum}' will use a temporary
    //usr/lib/gcc-lib/ntox86/2.95.3/../../../../include/g++-3/iostream.h:206: in passing argument 1 of `istream:perator >>(int &)'

    ====================================

    How do I solve this? Any thoughts?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main ()
    {
        int n;
        cin >> setiosflags(ios::skipws) >> n;
        cout << n << endl;
        return 0;
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    6
    Awesome!!
    Thank you...hk_mp5kpdw

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM