Like Tree2Likes

constant integer class variable errors

This is a discussion on constant integer class variable errors within the C++ Programming forums, part of the General Programming Boards category; You might try something like this: Code: int rn; std::string name, ccnum; std::ifstream fin("input.txt"); if (!fin) { std::cerr << "Error ...

  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.
    Elysia likes this.
    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
    67
    Got it to work! Thank you all so much for your help!

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    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.

Page 2 of 2 FirstFirst 12
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-03-2012, 11:56 PM
  3. integer constant data types
    By password636 in forum C Programming
    Replies: 3
    Last Post: 11-22-2011, 08:38 AM
  4. integer constant is too large for type
    By Abda92 in forum C++ Programming
    Replies: 8
    Last Post: 02-09-2008, 10:47 AM
  5. integer to constant char w/o using itoa()
    By kes103 in forum C++ Programming
    Replies: 1
    Last Post: 01-06-2003, 09:42 PM

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