Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   strings in C++ (http://www.go4expert.com/forums/strings-in-cpp-t5629/)

tailhook123 3Aug2007 03:33

strings in C++
 
I've been trying to setup visual studio and have run into a problem getting strings to work.

Code:

// stringtest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>

int _tmain(int argc, _TCHAR* argv[])
{
        string Mystring("ABC");

        int a = 0;

        return 0;
}

Just trying to get a simple string into the program but it won't recognize the 'string' variable. I've included the #include <string>.. is this a problem with needing to setup an include directory so that VS 2005 knows where to look or something else?

DaWei 3Aug2007 06:19

Re: strings in C++
 
Just including <string> is not enough. After all, you might define a string type of your own. The string class, as declared by <string> lives in the std namespace. You will need to quality your references by using something like, std::string MyString = "ABC";, or, alternatively, place the statement, "using std::string;" ahead of any usage. You need to be careful with "using" directives. You particularly need to be careful with an all-encompassing statement such as, "using namespace std;".

If you import every name in the std namespace (or even those in just string), you increase your chances of clashes with names that you come up with for your own code.


All times are GMT +5.5. The time now is 12:31.