如何在头文件c ++中声明一个wstring [英] How to declare a wstring in a header file c++
问题描述
您好我正在尝试在各种类中使用wstring变量,所以我想如果我把它放在公共头文件下我就可以使用它。
我有这个 - >
Hi I am trying to use a wstring variable in various classes so I thought if I put it in a header file under public I would be able to use it.
I have got this ->
#ifndef _TWITTER_H_
#define _TWITTER_H_
class Twitter
{
public:
void call();
void run_internal();
wstring newName;
};
#endif
但我收到这些错误 - > ;
错误20错误C4430:缺少类型说明符 - 假设为int。注意:C ++不支持default-int engine \twitter.h 9 1引擎
和
错误19错误C2146:语法错误:在标识符'newName'之前缺少';'\ engine \twitter.h 9 1引擎
我很困惑我不知道为什么。
任何帮助都会受到赞赏。
马克
But i get these errors ->
Error 20 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int engine\twitter.h 9 1 Engine
and
Error 19 error C2146: syntax error : missing ';' before identifier 'newName' \engine\twitter.h 9 1 Engine
I am quite confused as I don't know why.
Any help would be appreciated.
Mark
推荐答案
您可以在头文件中包含字符串
标题,或者在之前包含 在使用它的每个源文件中twitter.h
。
当然你还需要使用命名空间std;
指令。
You either include thestring
header in your header file or, alternatively, include it beforetwitter.h
in every source file using it.
Of course you need also theusing namespace std;
directive.
你必须在声明wstring的顶部包含标题。
喜欢
you must include the header at the top in which the wstring is declared.
like
#include <string>
这篇关于如何在头文件c ++中声明一个wstring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!