storing characters read from text file in 2 different string

This is a discussion on storing characters read from text file in 2 different string within the C++ Programming forums, part of the General Programming Boards category; hello, I wanted to ask you all a question. suppose that my c++ program has read from a text file ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    9

    storing characters read from text file in 2 different string

    hello,
    I wanted to ask you all a question.
    suppose that my c++ program has read from a text file a set of characters like the one below using the command inData >> temp. i output the characters of the text file and stored all the characters in a string temp.
    this is how it appears in the c++ output window:

    ace
    Spades
    10
    Spades
    3
    Clubs
    King
    Spades
    5
    Spades

    Now i want to store the 'spades','spades','clubs','spades','spades' in a string known as string suit. And i want to store the 'ace','10','3','king','5' in another string to be known as string face.
    This is where i am stuck. I can't seem to understand how to do it. I think that i have to create 2 string array.
    i tried this:
    str= temp;
    //if(str!="Spades")
    //cout << str << endl;
    but it's not working.
    then i tried this:
    if(temp=='Spades')
    //str = temp-'Spades';
    it's definitely not working.
    if someone could plz help me....
    Thanks

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Why don't you first try to save ALL the data? You could use a string array, a class container, a struct container, or a vector, its all up to you. Try saving all the data then cout the data and report back with your output and the code.

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    33
    You could use just one array and hold the card number, 1 of 52 possibilities, as an integer.

    Let’s say there are 100 hands of 5 cards.

    Int My_hand[100][5];

    8 of Clubs
    King of Diamonds
    3 of Hearts
    Ace of Spades
    10 of spades

    My_hand[1][1] = 8
    My_hand[1][2] = 26 (King of Diamonds)
    My_hand[1][3] = 29
    My_hand[1][4] = 40
    My_hand[1][5] = 49

    Then loop thru 52 if statements:

    if My_hand[x][y] = 27
    print "Ace of Hearts"
    else if My_hand[x][y] = 28
    print "Two of Hearts" etc…

    Or you could use 2 arrays:

    Int My_hand_suit[100][5];
    Int My_hand_face[100][5];

    My_hand_suit[1][1] = 1
    My_hand_face[1][1] = 8

    My_hand_suit[1][2] = 2
    My_hand_face[1][2] = 13 (King of Diamonds) etc…

    Then 2 loops and 13 if statements.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with finding word frequency in a text file.
    By aeolusaether in forum C Programming
    Replies: 15
    Last Post: 04-04-2010, 10:59 PM
  2. storing text file contents into a string
    By m.mixon in forum C Programming
    Replies: 4
    Last Post: 07-20-2006, 12:52 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21