Thread: Is this possible?

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    2

    Is this possible?

    Hello!

    So I am new to programming in C++ but have had some minimal programming experience in the past.

    I am looking to create a program that will read in a variable number of words in a text file (will grow as I add new words to it), place them in an array variable (1 word per node), then select and print to the screen 10 random words from the array. This would be a program that would help me quiz myself on vocab words for learning foreign languages.

    I just wanted to check to see if this is possible to do before I start banging my head against the wall on it

    Thanks!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you're thinking "array", you're stuck in the old world -- C++ has better containers for this than an array.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    It's certainly possible. I'm not sure why you'd think otherwise.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    2
    Thanks
    What would I use if not an array?
    Would i have to put the text file like:

    #1
    "
    word1
    word2
    word3
    "

    or
    #2
    "
    word1 word2 word3
    "

    and would I just use a while loop until (ifstream wordfile, wordfile="")? to handle a dynamicly growing input file?

    Thanks!

  5. #5
    Registered User Kudose's Avatar
    Join Date
    Jun 2006
    Posts
    92
    How about vector?

    vector<string> should work for you.

    You could also use a list.

  6. #6
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    keep it simple and use arrays
    if you need functionality like resizing and erasing and reallocation use vector
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Axanar View Post
    Thanks
    What would I use if not an array?
    Would i have to put the text file like:

    #1
    "
    word1
    word2
    word3
    "

    or
    #2
    "
    word1 word2 word3
    "

    and would I just use a while loop until (ifstream wordfile, wordfile="")? to handle a dynamicly growing input file?

    Thanks!
    Yes, either one is fine.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  8. #8
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Quote Originally Posted by Hussain Hani View Post
    keep it simple and use arrays
    if you need functionality like resizing and erasing and reallocation use vector
    What's not simple about a vector? :P It'll probably make life easier if anything.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Hussain Hani View Post
    keep it simple and use arrays
    if you need functionality like resizing and erasing and reallocation use vector
    If anything, arrays are more difficult and error-prone than vectors.
    vector isn't difficult and is recommended since there is no fixed amount of lines. Just use push_back instead of assigning. It's a cinch.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed