Вопрос

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\nisampleclientdefs.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;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top