Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

uber_n00b

Where can I get vector&string?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone know where I can get the C++ header files and ? They appear on my comp but when I try to use code like that below, the compiler (VC++6) decides to tell me that string is not defined or ignore vector altogether: #include <string> #include <vector> void main() { vector<'string> iam; } would yield c:\blah.cpp(12) : error C2065: 'string' : undeclared identifier [edited by - uber_n00b on April 13, 2004 8:43:43 PM]

Share this post


Link to post
Share on other sites
Advertisement
Make sure the header files are located in the path that VS searches for standard includes. I'd reckon this should be setup upon installation automatically, though...

Also, you need to qualify your declarations with the std:: namespace identifier, as all standard C++ library code is in the std namespace:

std::string str;


You can use a using namespace std; directive at the top of your source file if you wish to avoid using all of the std:: qualifiers.

Finally, classes such as vector are templated; that is, they need to be declared with a type specifier:

std::vector< int> intvec; // Vector of ints
std::vector< SomeStruct> structvec; // Vector of SomeStructs
std::vector< float *> floatptrvec; // Vector of ptrs to float




Golem
Blender--The Gimp--Python--Lua--SDL
Nethack--Crawl--ADOM--Angband--Dungeondweller


[edited by - VertexNormal on April 13, 2004 8:49:00 PM]

Share this post


Link to post
Share on other sites
Ok I will try that now. For some reason 'using namespace std;' doesn't work on my new comp though but worked fine on the old one with the same compiler. Any ideas on that one?'

Edit - While it did reduce my errors I still get fundamental problems with data types. I don't understand why my compiler wont recognize something that is written on practically every C++ website.

[edited by - uber_n00b on April 13, 2004 8:57:39 PM]

Share this post


Link to post
Share on other sites
Make sure your include directories for VC++ are actually valid. When I''ve been teaching people to use the thing I''ve had incidents where they simply delete some important include directory.
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE
Make sure this, or something very similar to it (depending on where you installed Visual Studio) appears in the include directories.

If it does, try this snippet of code:

#include <vector>
#include <string>

int main()
{
std::vector<std::string> test;

return 0;
}


It should work. If it doesn''t, post the errors here and we''ll work it out, because something is seriously wrong. If it does work, try this next:

#include <vector>
#include <string>
using namespace std;

int main()
{
vector<string> test;

return 0;
}

Now I''ve used the using directive to avoid having to write std:: everywhere. If this works, you''re good to go. If not, post the errors.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!