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?
Printable View
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?
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();
Hi!
For file i/o information, check out the best tutorial on this topic:
http://www.cpp-home.com/FileIO_tutorial.php