Thread: Converting File Data Into Double

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    Converting File Data Into Double

    I am using files to store some numbers in my program. I am storing a string on one line and then a number on another and it repeats (so i've got a client/number sort of system). I can use getline to get that information out of the file but I can't use the number. I need to be able to perform addition and subtraction on the numer... how can I do this?

    Also, is there a way to edit a specific part of a file (ie. alter the number and leave the rest as is?).

    I am using Borland C++ Builder 5:

    Thanks for any help you can provide -
    retretret

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Read every other line into a double rather than a string.

    //get text
    in.getline(text,sizeof(text));
    //get double
    in >> d;

    >Also, is there a way to edit a specific part of a file (ie. alter the number and leave the rest as is?).

    You could read the whole file into an array of string/double structs, change the ones you want and then write them all back out to file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. Creating array from data file...
    By Crankit211 in forum C Programming
    Replies: 2
    Last Post: 12-06-2001, 09:45 PM