Results 1 to 3 of 3

Data input/output

This is a discussion on Data input/output within the Off Topic forums, part of the Entertainment category; So we're doing data input/output right now by ourselves, cause the professor refuses to treat these things in class... When ...
Page: 1


  1. #1
    Judas Iscariot
    Guest

    Default

    So we're doing data input/output right now by ourselves, cause the professor refuses to treat these things in class...

    When you have this for example

    ifstream inStream;
    inStream.open(sometextfile.txt);


    First line you open a stream, then it reads the values in the file, all is good and dandy.
    However, inStream holds all the values in the text I am assuming, so therefore I can do this:

    int Array[] = (inStream);


    If this is possible, I can make a pointer to this array and do all sorts of things to it, like bubblesort it and stuff, right?
    How would I go around declaring the size of the array without knowing the amount of elements in the text file? I'm not exactly sure how inStream reads and holds the information so i'm at a loss here.

    Thanks to anyone who replies

  2. #2
    evilwevel
    Guest

    Default

    eeeuhm let me start by saying i never had C++, only visual basic.net.

    we had an exercise like that, what i did was made a loop where it would redeclare the size of the array until the streamreader gave a "-1" value, meaning the end of the file.

    like this :

    do until streamreader1 <> -1 (or streamreader1.endofstream)
    index += 1
    redim preserve array1(index)
    array1(index) = streamreader.read (or readline)
    loop

    this would normally make the array larger by one free spot in wich a single sign or line is read into until the end of the file is reached.

    i hope it helped abit, as i said before i never had C++ so i don&#39;t know if it has the same commands

  3. #3
    TunaFishyMe
    Guest

    Default

    I dont remember if it was Java or C, i believe both can do it where you can always change the array size. But the guy above is also a solution. Find out the length of the file and then create that.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •