Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String array

Status
Not open for further replies.

strawberryman

Programmer
Feb 14, 2006
3
0
0
US
My program is below, and I am getting an error C2664, When I looked it up, I could only come up with a parameter error, but to me, it doesn't look like I am violating one. My program (so far) is supposed to place names into a string array.starting with [0][0], and going down the line,placing the names in the locations.



#include<iostream>
#include<string>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using namespace std;

int main()
{
//delcalre variables
signed int players=0;
int players1=0;
int game [16][16];
int n,m;
char array1 [256][256];

cout<<"How many players or teams?";
cin >> players;
if (players<=0)
{cout<<"Invalid number, must be positive- re-enter number:";
cin>>players;
}
//end if


for (string players2=0;players1<=players;players1=players1+1)
{
cout<<"Name of player or team:";
cin>>players2;
for (;players1<=players;array1[0][0]=array1[0][0]+1);
char t[20];
strcpy (t,players2);
 
Code:
for (string players2=0;players1<=players;players1=players1+1)
You can't add numbers to strings.


Code:
for (;players1<=players;array1[0][0]=array1[0][0]+1);
I have no idea what you're trying to do here, but it's probably wrong.


Code:
strcpy (t,players2);
You're trying to strcpy() a string to a char array. You could do it if you called the .c_str() function of players2, but why not use strings everywhere instead of mixing strings and char arrays?
 
What I am trying to do is place names into an array. Starting with location [0][0], and moving to [0][1] then [0][2] and so on, for as many players as the user inputs. I had initialized the array as a char array because I didn't think it was possible to initialize a string array, or is that legal? Would it be a better idea, to assign the names, that the user inputs, to numbers, then place those numbers in the array? If so how would I start that?
 
I am not sure what you are trying to do but if you want to add numbers to a string, try stringstream,

EG;

char somechars[10];
stringstream strNew;
int counter = 55;
string str1 ="Hello";
:
:
:

strNew<<somechars<<str1<<"/"<<counter<<str2

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top