Thread: constant integer class variable errors

  1. #16
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You might try something like this:
    Code:
        int rn;
        std::string name, ccnum;
    
        std::ifstream fin("input.txt");
        if (!fin) {
            std::cerr << "Error ...\n";
            std::exit(EXIT_FAILURE); // you may want to exit, or not...
        }
    
        while (fin >> rn) {
            fin >> name;  // Can the name have spaces? Then this won't work.
            fin >> ccnum;
            // With the appropriate Customer ctor you could do this:
            hotel.room[rn].assignCustomer(Customer(name, ccnum));
            // If hotel.room is a vector, you're better to use at() instead of [].
        }
    Last edited by oogabooga; 10-01-2013 at 11:15 AM.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  2. #17
    Registered User
    Join Date
    Nov 2012
    Posts
    73
    Got it to work! Thank you all so much for your help!

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If room is a vector, then you should consider using push_back. Depending on whether you want rooms to exist without customers, either solution may be preferable.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. integer constant is too large for 'long' type
    By rehman12390 in forum C++ Programming
    Replies: 2
    Last Post: 05-25-2012, 06:12 AM
  2. Replies: 5
    Last Post: 03-04-2012, 12:56 AM
  3. integer constant data types
    By password636 in forum C Programming
    Replies: 3
    Last Post: 11-22-2011, 09:38 AM
  4. integer constant is too large for type
    By Abda92 in forum C++ Programming
    Replies: 8
    Last Post: 02-09-2008, 11:47 AM
  5. integer to constant char w/o using itoa()
    By kes103 in forum C++ Programming
    Replies: 1
    Last Post: 01-06-2003, 10:42 PM