c++ <vector> 没有命名类型

标签 c++ c++11 types

所以我在我的 C++ 程序中遇到了一些类型问题。 这是代码:

#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;
}

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

    error: ‘directories’ does not name a type

在两条线上都试图 push_back 到目录 vector 。

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

最佳答案

你不能把语句放在函数外面,只能放在声明和定义之外。将您的代码放在 main 中。

关于c++ <vector> 没有命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22893299/

相关文章:

c++ - 需要帮助了解我的 while 循环中发生了什么

C++正则表达式搜索多行注释(/* */之间)

c++ - 用户态和内核态共享内存

c++ - 从 std::thread::id 结构中检索 Windows 线程标识符

python - 大 TSV 文件中 moSTLy 整数字符串列的 pandas read_csv dtype 推断不一致

c# - C# 中是否有一个类来处理几个 INT(范围为 2 INT-1-10)

c++ - boost asio - 来自一个线程的 SSL async_read 和 async_write

c++ - 读取(int fd,void *buf,size_t count): prevent implicit conversion

c++ - move 省略优化

scala - F[_] 和 F[T] 在 Scala 中用于类型构造函数时的区别