This is my current coding, in my header file

#ifndef _ADDRESSBOOK
#define _ADDRESSBOOK

const int MAXADDRESS = 25;

struct PERSON
{
char fName[25];
char lname[25];
char Address[100];

};

class addressBook
{
private:
PERSON people[10];
public:
addressBook();
addressBook(char *fName, char*lname, char *add);
addressBook(PERSON a);
addressBook(PERSON init[], int count);
bool addPerson(const PERSON &p);
bool getPerson(PERSON &p);
bool findPerson(char *lastName, PERSON &p);
bool findPerson(char *lastName, char *firstName, PERSON &p);
void bubbleSort();
void printBook();

};

#endif

I have to change this the

private:
PERSON people[10];

to a vector, so I tried declaring it like this

vector <PERSON> people;

but i keep getting error messages saying stuff like this

1>e:\c++ level 2\address book\address book\addressbook.h(17) : error C2143: syntax error : missing ';' before '<'
1>e:\c++ level 2\address book\address book\addressbook.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\c++ level 2\address book\address book\addressbook.h(17) : error C2238: unexpected token(s) preceding ';'
1>e:\c++ level 2\address book\address book\addressbook.cpp(20) : error C2065: 'people' : undeclared identifier


but that was how my teacher showed me I declare a vector. well actually, he showed me while using "vector <int> x;" but he said that I could use a struct as a base type..I think. Can anybody tell me why I'm getting these errors?

yes, I have 2 cpp files, I included it in both of them. I thought I was supposed to include them in the header file though, but when my teacher showed us an example he did it in the cpp files so thats how I've been doing it since then.

Try to include it also in your .h file.
AFAIK if you don't the compiler may not know what a vector is when it encounters vector<PERSON> people; The following compiled to me:

#include <iostream>
#include <vector>

using std::vector;
	  
 const int MAXADDRESS = 25;
      
struct PERSON {
	char fName[25];
	char lname[25];
	char Address[100];
};
      
class addressBook {
	private:
	vector<PERSON> people;
	public:
	addressBook() { }
	addressBook(char *fName, char*lname, char *add);
	addressBook(PERSON a);
	addressBook(PERSON init[], int count);
	bool addPerson(const PERSON &p);
	bool getPerson(PERSON &p);
	bool findPerson(char *lastName, PERSON &p);
	bool findPerson(char *lastName, char *firstName, PERSON &p);
	void bubbleSort();
	void printBook();
};
      
int main(void) {
	addressBook myaddress;
	return 0;
}

ahh okay, when I used
using std::vector;
then it would compile, before I tried it with just
#include <vector>
and It wasn't working. Thank you!

This article has been dead for over six months. Start a new discussion instead.