compiler rejecting string?

Started by
8 comments, last by Mayrel 19 years, 6 months ago
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
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
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>).
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
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.
umm thats not a source file. any way yeah i just needed to use std thanks guys [smile]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Oops, I need to read posts better :P I just saw the #include directives and assumed it was a source file...
#pragma once doesnt work with gcc/mingw(dev-c++'s compiler) you have to youse old fasioned include guards.

#ifndef HEADERSNAME_H__
#define HEADERSNAME_H__

//code here

#endif
not if you use version 4.9.9.0 you right it dosnt work with the older versions

you should get the latest version
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
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.
gcc has always supported #pragma, it being part of the C/C++ standard and all.

Recent versions of gcc support #pragma once, as you can see
here. However, it is considered obsolete.
CoV

This topic is closed to new replies.

Advertisement