Problem with tstring typedef

I had a problem trying typedef to create 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. Error in "ERROR here (1)":

Error 3 of error C2871: 'std': a namespace with this name does not exist \ nisampleclient \ nisampleclientdefs.h 16

If I delete the ad using namespace std;and change the ERROR HERE (2) to say typedef std::basic_string<TCHAR> tstring;, then I get the error message:

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

instead of this.

Thanks in advance.:)

+3
source share
2 answers

Include the title string( #include <string>rather than string.h;)).

, :

using namespace ...

... , -;)

: ++ C .h, c. #include <cstdlib> , , .

+7

std::basic_string . , :

 #include <string> //include this

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

Source: https://habr.com/ru/post/1794473/


All Articles