Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;-不';不要说出一种类型_C++ - Fatal编程技术网

C++ c++;-不';不要说出一种类型

C++ c++;-不';不要说出一种类型,c++,C++,我有个问题。当我尝试构建以下代码时,我得到: 'keywords' does not name a type ... 'whitespace' does not name a type 第18-19行和第22-24行。有人能帮忙吗?这是代码 /* * cpp2html.h * * Created on: Mar 6, 2014 * Author: vik2015 */ #ifndef CPP2HTML_H #define CPP2HTML_H #include <

我有个问题。当我尝试构建以下代码时,我得到:

'keywords' does not name a type
...
'whitespace' does not name a type
第18-19行和第22-24行。有人能帮忙吗?这是代码

/*
 * cpp2html.h
 *
 *  Created on: Mar 6, 2014
 *      Author: vik2015
 */

#ifndef CPP2HTML_H
#define CPP2HTML_H

#include <string>
#include <vector>
#define VERSION "0.1a"

using namespace std;

vector<string> keywords;
keywords.push_back("for");
keywords.push_back("white");

vector<string> whitespace;
whitespace.push_back("\n");
whitespace.push_back("\t");
whitespace.push_back(" ");

#endif
/*
*cpp2html.h
*
*创建日期:2014年3月6日
*作者:vik2015
*/
#ifndef CPP2HTML\u H
#定义CPP2HTML\u H
#包括
#包括
#定义版本“0.1a”
使用名称空间std;
向量关键词;
关键词:推回(“for”);
关键词:推回(“白色”);
向量空白;
空格。向后推(“\n”);
空格。推回(“\t”);
空格。将_向后推(“”);
#恩迪夫

您不能在全局范围内使用任意表达式(如函数调用),只有您的声明才允许在全局范围内使用

push_back
的调用必须在函数中,可能在
main
中。或者,如果要在定义这些对象时对其进行初始化,可以在C++11中执行此操作:

std::vector<std::string> keywords{ "for", "white" };
std::向量关键字{“for”,“white”};
或者在C++03中:

inline std::vector<std::string> getKeywords()
{
  std::vector<std::string> keywords;
  keywords.push_back("for");
  keywords.push_back("white");
  return keywords;
};
std::vector<std::string> keywords = getKeywords();
inline std::vector getKeywords()
{
std::向量关键词;
关键词:推回(“for”);
关键词:推回(“白色”);
返回关键字;
};
std::vector keywords=getKeywords();

此外,切勿使用命名空间std放置
在标题中。它会影响包含标题的所有代码,即使该代码不希望使用该指令。

Ohhh,我怎么没注意到?谢谢:)。我想现在对我来说已经太晚了。重复的排序: