开发者

Problem with tstring typedef

I am having a problem with trying to typedef myself a nice handy tstring (see below)

#ifndef _NISAMPLECLIENT_H_
#define _NISAMPLECLIENT_H_

#include <windows.h>
#include <stdlib.h>
using namespace std; // ERROR here (1)

#ifdef _UNICODE
#define CommandLineToArgv CommandLineToArgvW
#else
#define CommandLineToArgv CommandLineToArgvA
#endif

typedef basic_string<TCHAR> tstring; // ERROR HERE (2)

I get a compiler error when trying to compile this. The error at "ERROR here (1)" is :

Error 3 error C2871: 'std' : a namespace with this name does not exist \nisampleclient\nisa开发者_如何学Pythonmpleclientdefs.h 16

If I remove the using namespace std;declaration and change ERROR HERE (2) to say typedef std::basic_string<TCHAR> tstring;then I get an error:

Error 3 error C2653: 'std' : is not a class or namespace name \nisampleclient\nisampleclientdefs.h 23

at that point instead.

Thanks in advance. :)


Include the string header (#include <string>, not string.h ;)).

Also, don't ever use:

using namespace ...

... in headers unless you want to call down the wrath of your fellow developers ;)

Side-note: in C++ most of the traditional C standard headers have counter-parts without .h extension but with a leading c. In your case #include <cstdlib> would be the better choice, although it depends on the compilers you use whether there is an actual difference.


std::basic_string class template takes three arguments. So you've to do this:

 #include <string> //include this

 typedef std::basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR> > tstring;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜