[英]How to print / check value of vector in C++
I just want to check the value of the variable as the code runs (like you can do in Matlab by just typing the name of the variable). 我只想在代码运行时检查变量的值(就像您在Matlab中只需键入变量名即可)。 I inserted one line of code cout << img_names;
我插入了一行代码cout << img_names;
in a sample open source code but got no operator "<<" matches these operands
in error list of visual studio. 在示例开源代码中,但no operator "<<" matches these operands
Visual Studio错误列表no operator "<<" matches these operands
。 However, I see cout being used fine in other parts of the sample code. 但是,我发现示例代码的其他部分都很好地使用了cout。 Below is the beginning part of the sample code where cout is inserted: 以下是插入cout的示例代码的开始部分:
#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...
How do I use cout properly to get the variable values or is there an easier way? 如何正确使用cout来获取变量值,或者有更简单的方法吗?
operator <<
is not defined for std::vector
because there is no standard way to print that type. 没有为std::vector
定义operator <<
,因为没有标准的方法可以打印该类型。 You can implement your own like so 您可以像这样实现自己的
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.