Saturday, May 22, 2010

C++ Strings and Structs!!!!! HELP BASIC C++?

This is my struct:





struct PlayerRecord


{





string playerID;


int playerNum;


int playerPoints;





};





I want to ask the user for the Player name, Players number and Player points save it in the struct and then print out the struct in a table.


I was using cin %26gt;%26gt; for the name but it splits the name when a space is added I want to use getline but dont know how to call it and save it in the struct unless it involves a file. I needhelp also in saving the answers into the struct. Thanks code will be helpful so I can see what to do

C++ Strings and Structs!!!!! HELP BASIC C++?
cin.getline(PlayerRecord.playerID);
Reply:DONT HOLD ME TO THIS





I believe cin is for character in, ie, one, not a string. I think you want to either make an array and make the program get each character looped to fill the entire array, ie, cin fills one, then two then three so on....


More than likely you should just use the stream in commands (i dont know what htey are) to get the entire stream, and then put the characters put into a word as an array. Check out the website below - FANTASTIC website.


No comments:

Post a Comment