Reading from FILES

char FILENAME[100];
ifstream SurveyFile;
SurveyFile.open(FILENAME)
while (!SurveyFile.eof)
{
here I need a code to read from the file character by character, and according to different delimiters I need to store these characters in either a char array or an int array for later use
}

for example, if each line starts with an integer then ';' then 2 strings then ';' then integer ',' integer ',' integer ',' etc... I need to store the first integer in array A (A[0]) then string1 in string B1[0] string2 in string B2[0] and finally each integer in int 2 dimentional array C such that:
C[0][0] is the first , C[0][1] second, C[0][2] etc...
then for the other lines same deal..

Any ideas?
closed account (28poGNh0)
Put YouFile.txt in c: driver and this code in your compiler

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# include <iostream>
# include <fstream>
using namespace std;

int main()
{
    ifstream in("c:\\YourFile.txt");

    if(in)
    {
        while(in)
            cout << char(in.get());
    }else cout << "Cannot find this file " << endl;
}

This sounds good, I needed to do some parsing and detect errors so I actually ended up using this

c = surveyFile.get(); to get values char by char

with the same declarations you gave, except I also ask the user to give me the file's name.
Thank you for your help!

Now I have a problem figuring out how I can check if a file I want to output to is good, open or anything...is it like for ifstream?

Thanks again!
Last edited on
Topic archived. No new replies allowed.