ifstream and opening a file

i have a document named wordfind.in which i am trying ot read the contents of each letter into the a two demintional array. can anyone offer help on how to do this this is the code that i have writen so far.

int main()
{
//Greeting
cout << "This program puts characters of a doc into an array
";


ifstream inStream;
inStream.open(wordfind.in());
assert(wordfind.in.is_open());

for(;;)
{
inStream >> reading;
if(reading.eof()) break;
}

inStream.close();
}

Comments

  • : i have a document named wordfind.in which i am trying ot read the contents of each letter into the a two demintional array. can anyone offer help on how to do this this is the code that i have writen so far.
    :
    : int main()
    : {
    : //Greeting
    : cout << "This program puts characters of a doc into an array
    ";
    :
    :
    : ifstream inStream;
    : inStream.open(wordfind.in());
    : assert(wordfind.in.is_open());
    :
    : for(;;)
    : {
    : inStream >> reading;
    : if(reading.eof()) break;
    : }
    :
    : inStream.close();
    : }
    :

    [blue]Why read one char at a time? If you want to store an entire line at one time, then use inStream.getline(buf[line], MAXLEN - 1);

    Check the boundaries before trying to assign anything. :P

    char buf[MAXLINE][MAXLEN];
    inStream.get(buf[line][index++]);

    [/blue]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion