c ++编译选择错误的命名空间

cod*_*fun 0 c++ string namespaces visual-studio-2010

我正在为我的项目使用OpenCV库,并使用命名空间"cv"和"std"作为我的源文件.我想使用字符串split函数根据分隔符拆分字符串.但是"split"函数默认为命名空间"cv"并显示与错误参数相关的错误,因为它期望与OpenCV slpit函数相关的参数.

可以做些什么来克服这个问题?我看到同一个函数在另一个源文件中运行正常,即使那个函数同时具有std和cv空间.

这些是我在两个文件中包含的标题 -

#include "stdafx.h"
#include <unordered_map>
#include <iostream> // for standard I/O
#include <fstream>
#include <string>   // for strings
#include <iomanip>  // for controlling float print precision
#include <sstream>  // string to number conversion
Run Code Online (Sandbox Code Playgroud)

doc*_*ove 10

避免将using namespace std;using namespace cv;你的代码,尤其是在头.
如果您无法阻止自己,请完全符合您需要的功能,例如

std::split(...)
Run Code Online (Sandbox Code Playgroud)

  • 标准中没有分裂.但是,还有boost :: std (2认同)