Public Group

compiler rejecting string?

This topic is 5121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

ok i dont know why but my compiler seems to be rejection string heres my code
#include "SDL.h"//duh
#include "Tile.h"// so we can hav the tile lists
#include <string.h>
#include <vector.h>// because they are better and more flexible then arrays
#pragma once
class Map
{
protected:
int m_tileHeight;
int m_tileWidth;//size of the tiles used on this preticular map
int m_Height; // in tiles
int m_Width; // in tiles
public:
Map(int width, int height, vector<Tile*> tile,int tileheight, int tilewidth,vector<string> szFiles);//intializing all member variables
vector<string> m_szFiles;
Tile *m_tilelist[];
vector<Tile*> m_tilelistvec;
vector<vector<int> >  MapOver;
void SetFiles(vector<string> ok);
int GetHeight()                                  {return m_Height*m_tileHeight;};
int GetWidth()                                   {return m_Width*m_tileHeight;};
void LoadMap(int MapOver[]);//may be used if i decide to load map from a txt file
void InitImages(vector<string> szFiles, vector<Tile*> tilelist);
void InitImages(vector<Tile*> tilelist);
void InitMap(vector< vector <int> > Map);
void DrawMap(SDL_Surface *screen,vector< vector<int> > MapOver,int tilelistsize);
};


i get this error "14 C:\Dev-Cpp\projects\HI\Map.h `string' was not declared in this scope

Share on other sites
You need to put std:: in front of it, or put a using namespace std; at the top of your file.

I would also recommend using the non .h versions of the include files (#include <vector> and #include <string>).

Share on other sites
Two things:

1) There is no ".h" at the end of the C++ standard library headers. It should be

#include <string>
#include <vector>

2) string and vector are within the namespace "std". In any of your own header files, it is best to prefix any use of "string" or "vector" with "std::", thus becoming "std::string" or "std::vector". In your own .cpp files, it is usually considered acceptable to add the line "using namespace std;" near the top, so that you don't have to type out "std::" all the time.

Share on other sites
Additionally, theres no point in adding #pragma once to a source file. #pragma once tells the compiler to only compile this file once. Which it does with source files anyway.

Share on other sites
umm thats not a source file. any way yeah i just needed to use std thanks guys [smile]

Share on other sites
Oops, I need to read posts better :P I just saw the #include directives and assumed it was a source file...

Share on other sites
#pragma once doesnt work with gcc/mingw(dev-c++'s compiler) you have to youse old fasioned include guards.

//code here

#endif

Share on other sites
not if you use version 4.9.9.0 you right it dosnt work with the older versions

Share on other sites
Hmm i have been under the impression that every version of gcc up to the latest 3.3 didnt support the #pragma preprocessor, I still prefer #ifndef#define#endif for portability though.

Share on other sites
gcc has always supported #pragma, it being part of the C/C++ standard and all.

here. However, it is considered obsolete.

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 10
• 12
• 17
• Forum Statistics

• Total Topics
632909
• Total Posts
3009172
• Who's Online (See full list)

There are no registered users currently online

×