首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在C++中打印/校验向量值

如何在C++中打印/校验向量值
EN

Stack Overflow用户
提问于 2016-04-05 04:06:18
回答 1查看 96关注 0票数 0

我只想在代码运行时检查变量的值(就像在Matlab中键入变量的名称一样)。我在示例开源代码中插入了一行代码cout << img_names;,但在visual的错误列表中获得了no operator "<<" matches these operands。但是,我看到cout在示例代码的其他部分中使用得很好。下面是插入cout的示例代码的开头部分:

代码语言:javascript
复制
#include <iostream>
#include <fstream>
#include <string>
#include "opencv2/opencv_modules.hpp"
#include <opencv2/core/utility.hpp>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/stitching/detail/autocalib.hpp"
#include "opencv2/stitching/detail/blenders.hpp"
#include "opencv2/stitching/detail/timelapsers.hpp"
#include "opencv2/stitching/detail/camera.hpp"
#include "opencv2/stitching/detail/exposure_compensate.hpp"
#include "opencv2/stitching/detail/matchers.hpp"
#include "opencv2/stitching/detail/motion_estimators.hpp"
#include "opencv2/stitching/detail/seam_finders.hpp"
#include "opencv2/stitching/detail/util.hpp"
#include "opencv2/stitching/detail/warpers.hpp"
#include "opencv2/stitching/warpers.hpp"

using namespace std;
using namespace cv;
using namespace cv::detail;

static void printUsage(){ ... }

// Default command line args
vector<String> img_names;
bool preview = false;
bool try_cuda = false;
double work_megapix = 0.6;
double seam_megapix = 0.1;
double compose_megapix = -1;
float conf_thresh = 1.f;
string features_type = "surf";
string ba_cost_func = "ray";
string ba_refine_mask = "xxxxx";
bool do_wave_correct = true;
WaveCorrectKind wave_correct = detail::WAVE_CORRECT_HORIZ;
bool save_graph = false;
std::string save_graph_to;
string warp_type = "spherical";
int expos_comp_type = ExposureCompensator::GAIN_BLOCKS;
float match_conf = 0.3f;
string seam_find_type = "gc_color";
int blend_type = Blender::MULTI_BAND;
int timelapse_type = Timelapser::AS_IS;
float blend_strength = 5;
string result_name = "result.jpg";
bool timelapse = false;
int range_width = -1;

static int parseCmdArgs(int argc, char** argv){ ... }

int main(int argc, char* argv[])
{
#if ENABLE_LOG
    int64 app_start_time = getTickCount();
#endif

#if 0
    cv::setBreakOnError(true);
#endif

    int retval = parseCmdArgs(argc, argv);
    cout << img_names;
    if (retval)
        return retval;

much more code continues...

如何正确地使用cout来获取变量值,或者是否有更简单的方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-05 04:30:21

operator <<不是为std::vector定义的,因为没有打印该类型的标准方法。您可以这样实现您自己的

代码语言:javascript
复制
std::ostream& operator<< (std::ostream& out, const std::vector<String>& vec)
{
    for (int i = 0; i < vec.size(); i++)
        out << vec[i] << " "; // or whatever formatting you like

    return out;
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36416933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档