Thread: c++ equivalent to java's Integer class

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    3

    c++ equivalent to java's Integer class

    I'm a Java programmer starting out with C++. I'm reading input from a text file with each line in the form of a date like "12/03/1990". I need to validate the month in the range of 01-12. In Java I would do this:

    Code:
    String s = "12/03/1990";
    String ss = "";
    for (int i=0;i<2;i++) {
    ss += s.charAt(i);
    }
    int n = Integer.parseInt(ss);
    boolean x = (n >= 1 || n <= 12) ? true : false;
    Is there a class in C++ that can parse a string for numbers?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    stringstream seems to be what you want.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  2. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 05:11 PM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  4. Equivalent of Java's "super" keyword
    By JasonLikesJava in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2002, 10:21 AM