c ++< vector>没有命名类型 [英] c++ <vector> does not name a type

查看:115
本文介绍了c ++< vector>没有命名类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的c ++程序遇到类型问题。
这是代码:

So I'm having some type problems in my c++ program. Here is the code:

#include "NHSFileparser.h"
#include "NHSFileController.h"
#include <string>
#include <vector>       

std::string databasepath = "/media/sf_Documents/Skola/MVK/testdb/";
std::string dblang = "english";
std::vector<std::string> directories;
std::string directory1 = "/media/sf_Documents/Skola/MVK/testdata/";
std::string directory2 = "/media/sf_Documents/Skola/MVK/testdata2/";
directories.push_back(directory1);
directories.push_back(directory2);
std::vector<std::string> queryterms;
std::vector<std::string> return_files;

int main() {
NHSFileController fc(directory1, databasepath);
bool b = fc.addDirectory(directory1);
NHSDatabase database(databasepath, dblang);
split( queryterms, "test", boost::is_any_of("_")); //Split on lots of chars
std::cout << "Queryterms set." << std::endl;
database.query(queryterms, return_files);
std::cout << return_files.size() << std::endl;
if (return_files.size() > 0){
    std::cout << "File found: " << return_files[0] << std::endl;
}
return 0;
}

当我使用 g ++ 4.6 -std = c ++ 0x 在Ubuntu 12.04上出现以下错误:

And when I compile using g++ 4.6 and -std=c++0x on Ubuntu 12.04 I get the following error:

    error: ‘directories’ does not name a type

到目前为止,我发现的所有问题都是没有正确声明std :: vector的问题,我(据我所知)

Everything I've found so far is problems with not declaring std::vector properly, which I (to the extent of my knowledge) have done.

推荐答案

您不能将语句放在函数外,只能放在声明和定义外。将您的代码放入 main

You cannot put statements outside functions, only declarations and definitions. Put your code inside main.

这篇关于c ++&lt; vector&gt;没有命名类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆