Thread: Help on obtaining an array through a class!!!

  1. #1
    Registered User
    Join Date
    Apr 2006
    Location
    Nacogdoches, TX
    Posts
    1

    Question Help on obtaining an array through a class!!!

    I have a homework assignment and i can't figure out how to cin from a file that contains the data with a command and two doubles such as:
    r 10.3 4.6
    r 5.7 6.2
    p 2.1 3.6
    etc.... the two numbers need to go into one element of the array
    so that they can be manipulated and continue adding elements until the quit command is reached.......it's a little hard to explain but can anyone help me.....PLEASE!!!!!
    Thanx Alot!

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    post what you've done so far and where you're having trouble. We're happy to give you a hand, but no-one will do your homework for you.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    You need to use ifstream to grab input from your file, if that is what you meant. The header file is fstream.h; try looking it up . Make sure you get the parsing working before you try to write the rest of your program.

    the two numbers need to go into one element of the array
    That's impossible. Maybe what you want to do is make a 2d array.

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    >>That's impossible.
    Not necessarily
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    Well, true, you could use a char array or something, but why would you want to do that?

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by joeprogrammer
    Well, true, you could use a char array or something, but why would you want to do that?
    What!? Use a(n array of objects of some) class or a struct? Who would ever want to do that?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  2. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM
  3. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  4. Replies: 4
    Last Post: 09-12-2001, 02:05 PM