read data from a file

hello everyone...
can someone help me to solve my task??
i need to use visual c++ to read a sample of data from txt file...
the sample of data in txt file is like this...


100 200 300
400 500 600
700 800 900
100 800 900

i have to read the data and display it...
can u give me a sample of coding to solve this matter..
thanks...

Comments

  • : hello everyone...
    : can someone help me to solve my task??
    : i need to use visual c++ to read a sample of data from txt file...
    : the sample of data in txt file is like this...
    :
    :
    : 100 200 300
    : 400 500 600
    : 700 800 900
    : 100 800 900
    :
    : i have to read the data and display it...
    : can u give me a sample of coding to solve this matter..
    : thanks...
    :


    If the file is text-based, you just need to open the file in text mode and use the common file handling functions to read integers. Perhaps you could try to be more specific with what you need help with?

    Note that code-begging is nowadays against the rules. If you ask for someone to provide you with the full source without any effort made by yourself to solve the problem, the post will be removed from this message board.
  • : : hello everyone...
    : : can someone help me to solve my task??
    : : i need to use visual c++ to read a sample of data from txt file...
    : : the sample of data in txt file is like this...
    : :
    : :
    : : 100 200 300
    : : 400 500 600
    : : 700 800 900
    : : 100 800 900
    : :
    : : i have to read the data and display it...
    : : can u give me a sample of coding to solve this matter..
    : : thanks...
    : :
    :
    :
    : If the file is text-based, you just need to open the file in text
    : mode and use the common file handling functions to read integers.
    : Perhaps you could try to be more specific with what you need help
    : with?
    :
    : Note that code-begging is nowadays against the rules. If you ask for
    : someone to provide you with the full source without any effort made
    : by yourself to solve the problem, the post will be removed from this
    : message board.



    hye lundin...
    actually i'm new in visual c++, i hope u can guide me to solve my problem..
    i'm very2 appreciate if u could do so..
    nway, i've already know how to open the file, but i don't know how to display it...
    actuly i want to make program that when i click button the program read from the file "test.txt" which contain integer, then the program display each value in that file..
    this is my coding...



    int mysub(int argc, char** argv)
    {
    ifstream fin;
    ofstream fout;

    string file = "test.txt";

    fin.open(file); // open file
    fin.close();


    fout.open(filename); // open file for writing.
    fout.close(); // always close when done.

    return 0; // always return 0 to indicate sucess to the OS.
    }

    #pragma endregion
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

    mysub();// utk isi subrutin


    }

  • Reading and writing from files is really easy, the "fin" and "fout" variables you've created work exactly like cin and cout. Just use fin and place the result in integers, and there you have it.
  • : : : hello everyone...
    : : : can someone help me to solve my task??
    : : : i need to use visual c++ to read a sample of data from txt file...
    : : : the sample of data in txt file is like this...
    : : :
    : : :
    : : : 100 200 300
    : : : 400 500 600
    : : : 700 800 900
    : : : 100 800 900
    : : :
    : : : i have to read the data and display it...
    : : : can u give me a sample of coding to solve this matter..
    : : : thanks...
    : : :
    : :
    : :
    : : If the file is text-based, you just need to open the file in text
    : : mode and use the common file handling functions to read integers.
    : : Perhaps you could try to be more specific with what you need help
    : : with?
    : :
    : : Note that code-begging is nowadays against the rules. If you ask for
    : : someone to provide you with the full source without any effort made
    : : by yourself to solve the problem, the post will be removed from this
    : : message board.
    :
    :
    :
    : hye lundin...
    : actually i'm new in visual c++, i hope u can guide me to solve my
    : problem..
    : i'm very2 appreciate if u could do so..
    : nway, i've already know how to open the file, but i don't know how
    : to display it...
    : actuly i want to make program that when i click button the program
    : read from the file "test.txt" which contain integer, then the
    : program display each value in that file..
    : this is my coding...
    :
    :
    :
    : int mysub(int argc, char** argv)
    : {
    : ifstream fin;
    : ofstream fout;
    :
    : string file = "test.txt";
    :
    : fin.open(file); // open file
    : fin.close();
    :
    :
    : fout.open(filename); // open file for writing.
    : fout.close(); // always close when done.
    :
    : return 0; // always return 0 to indicate sucess to the OS.
    : }
    :
    : #pragma endregion
    : private: System::Void button1_Click(System::Object^ sender,
    : System::EventArgs^ e) {
    :
    : mysub();// utk isi subrutin
    :
    :
    : }
    :
    :

    [color=Green]ige> Are you trying to display it onto the console? If Yes, then you can simply use cout.
    If you are trying to display it on a GUI, text box or something, then you need to do some extra work. You need to read about how to interact with the GUI.[/color]
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