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

Recommended Answers

All 2 Replies

Your phrasing is a little awkward, so I might be missing something. But, if I'm understanding your question correctly, you should be able to simply break it into 2 input statements.

inFile >> face >> suit;

Then, you can manipulate or store face and suit as you see fit.

Thankss...
I tried this but the 2 string face and suit is only storing the ace and spades.
Here's what i tried next.

string face[50]
while(inData >> face)
            {
              for(int i = 0; i<face.length(); i++)
              {
              if((face!="of")&&(i%2==0))
              cout << face[i] << endl;
              }
              }

but i think i made some mistakes there. because it's not compiling.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.