I/O help

This is a discussion on I/O help within the C++ Programming forums, part of the General Programming Boards category; its initialised Code: char num_students[MAXCHARS]; Code: inFile.getline(num_students,MAXCHARS, ' '); inFile>>num_students; cout << "Number of Students" << num_students <<endl; i get ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    18

    I/O help

    its initialised

    Code:
    char num_students[MAXCHARS];
    Code:
    inFile.getline(num_students,MAXCHARS, ' ');
    inFile>>num_students;
    cout << "Number of Students" << num_students <<endl;
    i get the right number .. but.. i then need to use num_students. in a for loop.. but wont let me.. cause its a char..

    i change it to int.. but it doesnt work..
    how to i just pull one integer from a file..

    thanx

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    This will read the first integer from the file data.txt.

    Code:
    ifstream inFile("data.txt");
    int num_students;
    inFile >> num_students;
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    or you could use a get function

  4. #4
    Rebooted Inquirer's Avatar
    Join Date
    Apr 2002
    Posts
    281
    Code:
    int num_students;
    fin >> num_students;
    ~Inquirer

    [EDIT]
    Beaten again...
    [/EDIT]
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  5. #5
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    oh, you just found out huh?

  6. #6
    Rebooted Inquirer's Avatar
    Join Date
    Apr 2002
    Posts
    281
    shhhhhhhhhhhh.............


    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. asynchronized I/O == multiplexing I/O?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 07-24-2006, 10:06 AM
  2. why page based I/O can improve performance?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 06-12-2006, 07:42 AM
  3. Nonblocking I/O
    By fnoyan in forum Linux Programming
    Replies: 4
    Last Post: 11-29-2005, 03:37 PM
  4. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 04:14 PM
  5. WSAAsyncSelect I/O Mode :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-12-2002, 03:23 PM

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