Putting a structure containing a string in a header

AgentZap

Senior member
Sep 1, 2001
730
0
0
When I try to compile the header file below I get "listings.h(6): error C2146: syntax error : missing ';' before identifier 'accountNumber'"

I am using the .NET compiler.

"string" is not abuilt in data type, but in my main .cpp file I have a #include <string>. I have also tried #include <string> at the top of the header itself.

The header file i am trying to build looks similar to

#ifndef LISTTYPE

#define LISTTYPE

struct listType
{
string accountNumber; //use of string to handle alphanumeric data
string owner;
string street;
string city;
string phone;
};

#endif


How does one make use of strings in a header? This exact struct, when not used in a header, runs perfectly when I put it above main() in my actual program instead of the header.

Thanks
 
Apr 30, 2005
81
0
66
Possible problem:

string is part of the std namespace. Either qualify the type with the namespace ( e.g. std::string accountNumber ) or by polluting the global namespace ( e.g. using namespace std; )

Cheers