Thread: Simple File I/O

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    Simple File I/O

    It has been forever since I've programmed in C++, and I have sold off all of my programming reference books... I just need help in coding a routing to open a textfile to read 3 lines of 3 numbers, separated by spaces as such:

    10 20 30
    40 50 60
    70 80 90

    placing them into a 2d array... I'm having a hard time locating the procedures online as well... If someone could provide me with sample code or a link to an online source for such a task, it would be grateful.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    int MyVar;
    ifstream ReadFile;
    
    ReadFile.open("MyFile.txt", ios::in | ios::nocreate);
    if(!ReadFile.fail())
    {
       //Reads one integer
       ReadFile >> Myvar;
    
       ReadFile.close();
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    There are hundreds of samples of file I/O on this board. Search the board with "ifstream".

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question about file I/O.
    By The7thCrest in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2009, 05:15 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. simple file I/O question
    By loopshot in forum C Programming
    Replies: 2
    Last Post: 11-30-2006, 02:59 PM
  4. Simple file I/O question
    By Wanted420 in forum C++ Programming
    Replies: 4
    Last Post: 10-08-2003, 11:01 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM