Thread: I need help with reading file

  1. #1
    Adrive
    Guest

    Unhappy I need help with reading file

    hello,

    i wrote a program that would write in personal details of a person such as their age, sex ,address, name. So far i can make the program save all information into a file.

    But the problem is during reading. Since addresses and names have space(s) in between, how can i read the file correctly?? I can't guess how much space a user will enter.

    By the way, for characters i always use :

    cin.getline

    thats why it allows user to key in information with space in between.

    Please help?

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    c++ imposes no structure on files. That is up to you.
    In this case it may be better to use a fixed length record and binary file.For instance make each record 100 bytes long and split that up into separate fields as needed.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM