Thread: C++ text file output...specifics

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    6

    C++ text file output...specifics

    i attached my cpp file in this post
    it is a farely simple application that involves a bunch of little equasions and calculations, except i want it to output d, h, x, and nd into a text file, in that order.
    and then i want to be able to read d from the first line and h from the second...in another opengl related cpp that will render a drawing based on those four from the text file.

    i have looked at a bunch of online sources but can't get any of the ofstream...stuff to work.

    last question: in the cpp file that reads these 4 and renders an opengl drawing i would like to be able to have it refresh as i for example press enter. I have already activated the keyboard and such, lighting, and a pause key for stopping rotation, but how would i set a key to refresh/get updated values from the text file

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    6

    Unhappy anyone??????

    fine don't answer the above just answer this:
    i know how to output the numbers (not characters or strings) onto a text file, 4 lines and therefore 4 numbers/floats.

    now how can i read them in another program as floats and set them equal to something i intitialized and set as a float in this program. for example set line 1=x, line 2=y, line 3=z...
    pleeeeeese help

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    To read the values just use ifstream.

    double var1,var2,var3,var4;
    ifstream input("input.txt");
    input >> var1 >> var2 >> var3 >> var4;

    that would read in 4 double values from the text file

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    6
    thank you very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. I'm not THAT good am I?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-19-2006, 10:08 AM
  4. Outputting to a File Modified Text
    By alpha in forum C++ Programming
    Replies: 8
    Last Post: 11-24-2003, 08:39 PM
  5. Recording console window output to a text file?
    By HolySmiter in forum C++ Programming
    Replies: 3
    Last Post: 02-24-2002, 03:13 PM