Thread: Set Maximum Number of characters (Precision) for positive and Negative Values

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    224

    Set Maximum Number of characters (Precision) for positive and Negative Values

    Hi,

    I want to be able to jump to a particular line in a CSV file. I have read that in order to do so, each line must have the same size.

    Therefore, in writing the data to the file I want to set the number of characters to a specified/set number.

    I have tried:
    Code:
    file.setf(ios_base::fixed, ios_base::floatfield);
    	  file.precision(10);
    However, my issue is with negative values. Will negative values take up space?

    many thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I want to be able to jump to a particular line in a CSV file. I have read that in order to do so, each line must have the same size.
    If you want true random access files I suggest you investigate binary files. Text files are not really suited for random access. If you want to be able to jump to and read from a certain line it is possible, if you keep track of the file position where each line starts. However if you want to try to replace text in the middle of a file, that is a problem. It is usually not recommended to try to replace text in the middle of a text file, because it is not possible to erase a section, or insert text into a section. Text files are best suited for sequential access and appending data to the end of the file.

    Jim

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    224
    Thanks for the heads up jim. Will look in to this! cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. count the number of positive and negative numbers
    By Arex Bawrin in forum C Programming
    Replies: 5
    Last Post: 04-04-2011, 07:24 PM
  2. convert negative float to positive ???
    By manny in forum C Programming
    Replies: 4
    Last Post: 07-02-2009, 03:37 AM
  3. Negative Float Into Positive
    By Cero.Uno in forum C Programming
    Replies: 2
    Last Post: 02-17-2008, 03:13 AM
  4. How can i convert negative number to positive number ?
    By winsonlee in forum C Programming
    Replies: 2
    Last Post: 05-05-2004, 08:02 AM
  5. random number between negative and positive number
    By anomaly in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2003, 08:40 AM