//this is in a header file
struct QUESTIONS
{
char questiontext[80];
char questionanswer[80];
char wrongans1[80];
char wrongans2[80];
char wrongans3[80];
char refbook[20];
int refchapter;
float refpages;
};
//this is in a separate .cpp file
QUESTIONS* chapter1 = new QUESTIONS[3];
//QUESTIONS chapter1[3];
chapter1[0].questiontext = "How many engines does the Challenger 605 have?";
chapter1[0].answertext = '2';
chapter1[0].refchapter = 1;
I am using MS Visual C++ 2010 Express and the problem is that if I use either one of the declarations for chapter1, I get the red squiggly underline error thing underneath the 0 and the . (the dot) in all 3 of the chapter1[0].questiontext... assignments.
The error that is given to me when I hold the mouse over the 0 is:
"Error: the size of an array must be greater than zero"
And when I hold the mouse over the . I get the following error:
"Error: expected a declaration"
Can anybody see something obvious that I have done wrong? As far as I can see I have already created the array of QUESTIONS structures, so why can't I assign a value to any given value within the array?
Grey Wolf - I tested out your code in a program called Quincy 2010 and it worked out fine, but in my Visual Studio 2010 I still get the errors mentioned above :(
Sure you're compiling GreyWolf's code (as iHutch says, with the right headers - I had to add cstring)?
Your original code was broken (you were trying to assign a const char[47] to a const char[80]) but his is fine as it doesn't assign pointers around and instead copies data.
But when using .c_str() doesn't that result in a const char? This is not allowed within the SDK I will be using...or is there a way to convert it to a non const? Or am I completely wrong!!
@flyer53
If you wish to use a std::string with the windows api,
1 2 3 4 5
string str(size + 1, 0) // create an empty string with the required size,
// +1 to include room for the null character.
func(&str[0], str.size(), ...) // &str[0] is a char pointer to the first character,
// and str.size() represents the maximum number of characters.