I am trying to learn c++ by making a text game.
At the moment I have a problem.
I am using a string-array to hold my races.
1 2 3 4 5 6
|
std::string race[5];
race[0] = "God";
race[1] = "Human";
race[2] = "Orc";
race[3] = "Elf";
race[4] = "Dwarf";
|
And this neither fputs nor strcpy like so I tried this
1 2 3 4
|
char races[50];
int rX;
cin >> rX;
races = race[rX]
|
But this didn't work either. Got this error:
incompatible types in assignment of `std::string' to `char[50]' |
The thing I wanna do is a array that holds the different races and after that
put it in a different variable that will save the value in a text file.
And to use fputs with a string didn't work.
cannot convert `std::string' to `const char*' for argument `1' to `int fputs(const char*, FILE*)' |
Then to use strcpy didn't work either.
no matching function for call to `strcpy(char[50], std::string&)'
candidates are: char* strcpy(char*, const char*) |
Anyone know how I can do this?
If you didn't understand what I try to do it's this:
1. Start the program
2. Enter name, age, race
3. Save name, age and race in their own variables.
4. Use fputs to save the variables to a file
Name and age works perfect because they already are char but race is string
so it doesn't wanna work with fputs or strcpy and I have no idea how to go
around this.