Thread: file input

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    39

    Exclamation file input

    i know the total no of characters in an input file and have make an array of that size.i want to know how can i get all the elements of the file in the array?
    once a kohatian,always a kohatian!

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Use a for loop and get each individual char inside it.

    Code:
    #define size 100//or whatever the size is
    
    int counter;
    char array[size];
    ifstream infile("file.txt");
    for(counter=0;counter<size;counter++)  array [counter]=infile.get();

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    104
    Hi!

    For file i/o information, check out the best tutorial on this topic:
    http://www.cpp-home.com/FileIO_tutorial.php
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  4. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM