string array returning erros

for some reason the following code returns error "a function-definition is not allowed here before '{' token" all the time, cannot seem to figure out why, sorry, i am noob.

#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

using namespace std;

int main()
{
int i=0;
string group1;
string Group1[20][2]
{
{"State1","1"},
{"State2","2"},
{"State3","3"},
{"State4","4"},
{"State5","5"},
{"State6","6"},
{"State7","7"},
{"State8","8"},
{"State9","9"},
{"State10","10"},
{"State11","11"},
{"State12","12"},
{"State13","13"},
{"State14","14"},
{"State15","15"},
{"State16","16"},
{"State17","17"},
{"State18","18"},
{"State19","19"},
{"State20","20"}
};
struct CityState
{
bool asked;
char state[25];
char cirty[25];
}question[20];

cout << "Hello world!" << endl;
return 0;
}
Missing assignment operator '='

 
string Group1[20][2] =
yeah, that would be it. i am an idiot of monstrous proportion, thanks mate, appreciated...
dyslexia is the ultimate pain for this kind fo work
So now i have managed to get to here. The bold is where i get stuck. Obviously i am not understanding how to point to a specific CityState via pointers. What i want to do is check each struct if the bool is true, and if yes move on, else i will perform an operation on the struct. But not sure how to accomplish this.....

#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

using namespace std;

int main()
{
int i=0;
string test="";
string Group1[20][2]=
{
{"State1","1"},
{"State2","2"},
{"State3","3"},
{"State4","4"},
{"State5","5"},
{"State6","6"},
{"State7","7"},
{"State8","8"},
{"State9","9"},
{"State10","10"},
{"State11","11"},
{"State12","12"},
{"State13","13"},
{"State14","14"},
{"State15","15"},
{"State16","16"},
{"State17","17"},
{"State18","18"},
{"State19","19"},
{"State20","20"}
};
struct CityState
{
bool asked;
string state;
string city;
}question[20];
CityState * pointCS;
pointCS = question;
for(i=0;i<20;i++)
{
question[i].asked=false;
question[i].state=Group1[i][0];
question[i].city=Group1[i][1];
// cout << "the value of i is " << i << endl;
}
i=0;
for(i=0;i<20;i++)
{
test=*pointCS[][1];

// cout << "the value of i is " << i << endl;
}

i=0;
for(i=0;i<20;i++)
{
cout << "State: " << question[i].state << " City: " << question[i].city << "\n";
}
cout << "Hello world!" << endl;
return 0;
}
Consider putting the tags [code] and [/code] around your code to format it ;o)

I think you have too many square brackets on your array:

 
test=*pointCS[][1]; // what's with the first [] ? 


Also I suspect you don't want the dereference operator * there. Subscripting the array with [] dereference it already.

 
test=*pointCS[1]; // what's with the * ? 


And you seem to have typed the number 1 rather than the letter i

 
test=pointCS[1]; // Really number 1? Not i? 


And you seem to have failed to declare a type for variable temp

 
/* type?? */test=pointCS[i]; // What type is temp? 


Its hard to imagine how you could squeeze more errors into such a small piece of code. For that you should be commended!

So do you mean like this?
not quite sure what you mean above, very very confused person here.
have read through the bit about pointers on here a few times, but not getting it at all.
1
2
3
4
5
6
7
   for(i=0;i<20;i++)
    {
        pointCS=&question[i];
        test=pointCS;

            // cout << "the value of i is " << i << endl;
    }
And you seem to have failed to declare a type for variable temp



/* type?? */test=pointCS[i]; // What type is temp?

not sure what you are referring to here, i have no types temp anywhere, neither entioned nor assigned.
I think you most likely meant this:

1
2
3
4
for(i = 0; i < 20; i++)
{
    CityState test = pointCS[i];
}
Topic archived. No new replies allowed.