tstring typedef问题

我有一个问题,试图自己键入一个非常方便的tstring(见下文)
#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)
尝试编译时出现编译器错误。 “ERROR here(1)”中的错误是:   错误3错误C2871:'std':具有此名称的命名空间不存在 nisampleclient nisampleclientdefs.h 16 如果我删除
using namespace std;
declaration并将ERROR HERE(2)更改为ѭ2,然后我收到错误:   错误3错误C2653:'std':不是类或命名空间名称 nisampleclient nisampleclientdefs.h 23 在那一点上。 提前致谢。 :)     
已邀请:
包括
string
标题(
#include <string>
,而不是string.h;))。 此外,不要使用:
using namespace ...
...在标题中,除非你想要打倒你的开发者的愤怒;) 侧注:在C ++中,大多数传统的C标准接头都有对接部件,没有延伸
.h
但带有前导
c
。在你的情况下,
#include <cstdlib>
将是更好的选择,虽然它取决于你使用的编译器是否存在实际差异。     
std::basic_string
类模板有三个参数。所以你要做到这一点:
 #include <string> //include this

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

要回复问题请先登录注册