gpt4 book ai didi

c++ - tstring typedef 的问题

转载 作者:太空狗 更新时间:2023-10-29 19:47:00 27 4
gpt4 key购买 nike

我在尝试为自己输入一个方便的 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)”处的错误是:

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

如果我删除 using namespace std;声明并将 ERROR HERE (2) 更改为 typedef std::basic_string<TCHAR> tstring;然后我得到一个错误:

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

在那个时候。

提前致谢。 :)

最佳答案

包括 string header ( #include <string> ,而不是 string.h ;))。

此外,永远不要使用:

using namespace ...

...在标题中,除非你想激怒你的开发伙伴 ;)

旁注:在 C++ 中,大多数传统 C 标准头文件都有不带 .h 的对应部分扩展名,但带有前导 c .在你的情况下 #include <cstdlib>将是更好的选择,尽管这取决于您使用的编译器是否存在实际差异。

关于c++ - tstring typedef 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5106473/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com