I/O: std::basic_ostream

本文详细介绍了C++中std::basic_ostream类的功能及使用方法,包括构造函数、拷贝与移动操作、字符与字符串的输出、位置控制等关键特性,并通过示例展示了如何使用这些功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需要#include<ostream>:

template class std::basic_ostream提供高水平的字符输出操作,支持格式化的和非格式化的输出操作.

template<

    class CharT,
    class Traits = std::char_traits<CharT>
> class basic_ostream : virtual public std::basic_ios<CharT, Traits>
	

我们一般看到的:

std::ostream其实是 typedef std::basic_ostream<char> ostream.

std::wostream其实是 typedef std::basic_ostream<w_char> wostream.

 

构造函数:

public:
explicit basic_ostream( std::basic_streambuf<CharT, Traits>* sb );

protected:
basic_ostream( const basic_ostream& rhs ) = delete;
	
protected:
basic_ostream( basic_ostream&& rhs );

1,public explicit的构造函数接受一个std::basic_streambuf的指针作为参数.

2,delete删除的拷贝构造函数,也就是说Stream是无法被拷贝的.

3,protected的移动构造函数,也就是说后续继承了该类的其他类可以支持移动比如std::basic_ofstream

 

std::basic_ostream::operator=

protected:
basic_ostream& operator=( const basic_ostream& rhs ) = delete;
	
protected:
basic_ostream& operator=( basic_ostream&& rhs );

1,拷贝赋值符为delete的,也就是说是不支持拷贝的.

2,移动赋值运算符为protected的,也就是说后续继承了该类的其他类可以支持移动比如std::basic_ofstream.

 

std::basic_ostream::put

basic_ostream& put( char_type ch );
	

把字符ch放到当前output stream里其效果类似 std::cout<< ch;

如果给定的字符类型不符合当前stream的字符集造成输出失败那么当前流会被设置std::ios::badbit.

 

std::basic_ostream::write

basic_ostream& write( const char_type* s, std::streamsize count );
	

把s指向的字符数组的前count个字符插入到当前output stream,如果插入失败那么给当前流设置std::ios::badbit.

 

std::basic_ostream::tellp

pos_type tellp();
	

返回写入(写入指的是写入stream)位置.

如果当前output stream被设置了std::ios::failbit那么返回-1;

 

std::basic_ostream::seekp

basic_ostream& seekp( pos_type pos );

basic_ostream& seekp( off_type off, std::ios_base::seekdir dir);

1,设置绝对写入位置。

2,设置相对写入(写入指的是写入stream)位置(相对于我们给定的dir)

但是需要注意的是: stream中的cin, cout, cerr是不支持的. 另外pos_type是一个很复杂的类型并不是简单的long, unsigned long等等.

一般我们使用的时候直接使用: std::ios::pos_type就可以了并不用像Demo里面定义的这么麻烦

Demo:

#include <iostream>
#include <cstdlib>
#include <exception>
#include <streambuf>
#include <sstream>

int main()
{
	std::basic_string<char> str;
	std::basic_stringstream<char> strStream(str);

	std::fpos<std::char_traits<char>::state_type> pos = strStream.tellg();

	std::cout << pos << std::endl;

	return 0;
}

 

std::basic_ostream::operator<<

member function部分(用于给当前流设置flags, states以及对数字类型的输出 和 输出其他stream的streambuf):

basic_ostream& operator<<( short value );
basic_ostream& operator<<( unsigned short value );
		
basic_ostream& operator<<( int value );
basic_ostream& operator<<( unsigned int value );
	 	
basic_ostream& operator<<( long value );
basic_ostream& operator<<( unsigned long value );
		
basic_ostream& operator<<( long long value );
basic_ostream& operator<<( unsigned long long value );
	
basic_ostream& operator<<( float value );

basic_ostream& operator<<( double value );
basic_ostream& operator<<( long double value );
	 	
basic_ostream& operator<<( bool value );
	
basic_ostream& operator<<( const void* value );
		
basic_ostream& operator<<( std::basic_streambuf<CharT, Traits>* sb);
	
basic_ostream& operator<<(
    std::ios_base& (*func)(std::ios_base&) );
	 	
basic_ostream& operator<<(
    std::basic_ios<CharT,Traits>& (*func)(std::basic_ios<CharT,Traits>&) );
	
basic_ostream& operator<<(
    std::basic_ostream<CharT,Traits>& (*func)(std::basic_ostream<CharT,Traits>&) );

 

 

std::ios_base::seekdir类型:

std::ios::beg 定位到 文件(File)或者stream 开始位置.

std::ios::cur 定位到文件(File)或者stream当前位置.

std::ios::end 定位到文件(File)或者stream的尾部。

转载于:https://my.oschina.net/SHIHUAMarryMe/blog/746002

#include <iostream> #include <fstream> #include <vector> #include <Eigen/Core> #include <Eigen/Geometry> #include <g2o/core/base_vertex.h> #include <g2o/core/base_binary_edge.h> #include <g2o/core/base_unary_edge.h> #include <g2o/core/block_solver.h> #include <g2o/core/optimization_algorithm_levenberg.h> #include <g2o/solvers/dense/linear_solver_dense.h> #include <g2o/types/slam3d/vertex_se3.h> #include <g2o/types/slam3d/edge_se3.h> #include <g2o/core/eigen_types.h> #include <g2o/types/slam3d/types_slam3d.h> #include <opencv2/opencv.hpp> using namespace std; using namespace Eigen; struct Edge { size_t s; // Start index size_t e; // End index Isometry3d pose; // Relative pose between start and end }; class INS { public: void optimizeTrajectory(std::vector<Isometry3d> &poses) { std::vector<Edge> edgeData; for (size_t i = 0; i < poses.size() - 1; ++i) { Edge edge_data; edge_data.s = i; edge_data.e = i + 1; edge_data.pose = poses[i].inverse() * poses[i + 1]; edgeData.push_back(edge_data); } // 添加最后一个点到第一个点的边 Edge edge_data; edge_data.s = poses.size() - 1; // 最后一个点的索引 edge_data.e = 0; // 第一个点的索引 Isometry3d error_pose = poses[edge_data.s]; Isometry3d true_pose = error_pose * calibration_error_.Get(); LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); edge_data.pose = true_pose.inverse() * poses[edge_data.e]; edgeData.push_back(edge_data); std::unique_ptr<g2o::LinearSolverDense<g2o::BlockSolverX::PoseMatrixType>> linearSolver = std::make_unique<g2o::LinearSolverDense<g2o::BlockSolverX::PoseMatrixType>>(); g2o::OptimizationAlgorithmLevenberg *solver = new g2o::OptimizationAlgorithmLevenberg( std::make_unique<g2o::BlockSolverX>(std::move(linearSolver))); g2o::SparseOptimizer optimizer; optimizer.setAlgorithm(solver); optimizer.setVerbose(false); for (int i = 0; i < poses.size(); i++) { g2o::VertexSE3 *v = new g2o::VertexSE3(); v->setId(i); v->setEstimate(poses[i]); if (i == 0) { v->setFixed(true); } optimizer.addVertex(v); } for (const auto &pData : edgeData) { g2o::EdgeSE3 *edge = new g2o::EdgeSE3(); edge->setVertex(0, optimizer.vertex(pData.s)); edge->setVertex(1, optimizer.vertex(pData.e)); if (&pData == &edgeData.back()) { LogWarn("*******&pData == &edgeData.back()************"); edge->setInformation(Matrix6d::Identity() * 100000); } else { edge->setInformation(Matrix6d::Identity() * 0.001); } edge->setMeasurement(pData.pose); optimizer.addEdge(edge); } optimizer.initializeOptimization(); optimizer.optimize(500); for (int i = 0; i < poses.size(); i++) { g2o::VertexSE3 *vertex = dynamic_cast<g2o::VertexSE3 *>(optimizer.vertex(i)); poses[i] = vertex->estimate(); } LogWarn("Trajectory optimization successful !!!!!!!!!!"); } private: struct CalibrationError { Isometry3d Get() const { Isometry3d calib; calib.setIdentity(); calib.translate(Vector3d(0.1, 0.1, 0.1)); // Example calibration error calib.rotate(AngleAxisd(Deg2Rad(0.1), Vector3d::UnitZ())); // Example rotation error return calib; } }; double Deg2Rad(double deg) const { return deg * M_PI / 180.0; } CalibrationError calibration_error_; template<typename T> void LogInfo(const T& message) { cout << "[INFO] " << message << endl; } template<typename T> void LogWarn(const T& message) { cout << "[WARN] " << message << endl; } string matrixToString(const Matrix4d& matrix) { stringstream ss; ss << matrix; return ss.str(); } }; void generateSimulatedTrajectory(std::vector<Isometry3d>& poses, int numPoints) { double sideLength = 4.0; // 正方形的边长 double angleStep = INS().Deg2Rad(90.0); // 每个转角的角度 for (int i = 0; i < numPoints; ++i) { Isometry3d pose = Isometry3d::Identity(); switch (i % 4) { case 0: pose.translation() = Vector3d(sideLength * (i / 4), 0, 0); break; case 1: pose.translation() = Vector3d(sideLength * (i / 4 + 1), 0, 0); pose.rotate(AngleAxisd(angleStep, Vector3d::UnitZ())); break; case 2: pose.translation() = Vector3d(sideLength * (i / 4 + 1), sideLength, 0); pose.rotate(AngleAxisd(angleStep * 2, Vector3d::UnitZ())); break; case 3: pose.translation() = Vector3d(sideLength * (i / 4), sideLength, 0); pose.rotate(AngleAxisd(angleStep * 3, Vector3d::UnitZ())); break; } // 加入误差 pose.translate(Vector3d(rand() / double(RAND_MAX) * 0.1, rand() / double(RAND_MAX) * 0.1, rand() / double(RAND_MAX) * 0.1)); pose.rotate(AngleAxisd(INS().Deg2Rad(rand() % 2), Vector3d::UnitZ())); poses.push_back(pose); } } void drawTrajectory(const std::vector<Isometry3d>& poses, const std::string& title) { cv::Mat img(800, 800, CV_8UC3, cv::Scalar(255, 255, 255)); for (size_t i = 0; i < poses.size(); ++i) { Vector3d pos = poses[i].translation(); if (i > 0) { Vector3d prevPos = poses[i-1].translation(); cv::line(img, cv::Point((prevPos.x() + 4.0) * 100, (-prevPos.y() + 4.0) * 100), cv::Point((pos.x() + 4.0) * 100, (-pos.y() + 4.0) * 100), cv::Scalar(0, 255, 0), 2); } cv::circle(img, cv::Point((pos.x() + 4.0) * 100, (-pos.y() + 4.0) * 100), 3, cv::Scalar(0, 0, 0), -1); } cv::imshow(title, img); cv::waitKey(1); } int main() { srand(time(NULL)); int numTrajectoryPoints = 16; // 轨迹点数量(正方形的四个角重复四次) std::vector<Isometry3d> trajectory(numTrajectoryPoints); // 生成模拟轨迹 generateSimulatedTrajectory(trajectory, numTrajectoryPoints); // 显示优化前的轨迹 drawTrajectory(trajectory, "Before Optimization"); // 创建INS对象并进行优化 INS ins_optimizer; ins_optimizer.optimizeTrajectory(trajectory); // 显示优化后的轨迹 drawTrajectory(trajectory, "After Optimization"); cv::waitKey(0); return 0; } 报错:/usr/include/c++/9/ostream:523:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:528:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)’ 528 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c) | ^~~~~~~~ /usr/include/c++/9/ostream:528:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:548:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)’ 548 | operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s) | ^~~~~~~~ /usr/include/c++/9/ostream:548:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/ostream:702, from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/bits/ostream.tcc:321:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)’ 321 | operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s) | ^~~~~~~~ /usr/include/c++/9/bits/ostream.tcc:321:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:565:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)’ 565 | operator<<(basic_ostream<char, _Traits>& __out, const char* __s) | ^~~~~~~~ /usr/include/c++/9/ostream:565:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:578:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)’ 578 | operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s) | ^~~~~~~~ /usr/include/c++/9/ostream:578:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:583:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)’ 583 | operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s) | ^~~~~~~~ /usr/include/c++/9/ostream:583:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:691:5: note: candidate: ‘template<class _Ostream, class _Tp> typename std::enable_if<std::__and_<std::__not_<std::is_lvalue_reference<_Tp> >, std::__is_convertible_to_basic_ostream<_Ostream>, std::__is_insertable<typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type, const _Tp&, void> >::value, typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type>::type std::operator<<(_Ostream&&, const _Tp&)’ 691 | operator<<(_Ostream&& __os, const _Tp& __x) | ^~~~~~~~ /usr/include/c++/9/ostream:691:5: note: template argument deduction/substitution failed: /usr/include/c++/9/ostream: In substitution of ‘template<class _Ostream, class _Tp> typename std::enable_if<std::__and_<std::__not_<std::is_lvalue_reference<_Tp> >, std::__is_convertible_to_basic_ostream<_Ostream>, std::__is_insertable<typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type, const _Tp&, void> >::value, typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type>::type std::operator<<(_Ostream&&, const _Tp&) [with _Ostream = const char (&)[32]; _Tp = std::__cxx11::basic_string<char>]’: /home/guo/g2o仿真/src/optimize.cc:46:103: required from here /usr/include/c++/9/ostream:691:5: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’ In file included from /usr/local/include/eigen3/Eigen/Core:50, from /home/guo/g2o仿真/src/optimize.cc:4: /usr/include/c++/9/complex:552:5: note: candidate: ‘template<class _Tp, class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::complex<_Tp>&)’ 552 | operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) | ^~~~~~~~ /usr/include/c++/9/complex:552:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/hyper_graph.h:31, from /opt/ros/noetic/include/g2o/core/optimizable_graph.h:35, from /opt/ros/noetic/include/g2o/core/base_vertex.h:30, from /home/guo/g2o仿真/src/optimize.cc:6: /usr/include/c++/9/bitset:1538:5: note: candidate: ‘template<class _CharT, class _Traits, long unsigned int _Nb> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::bitset<_Nb>&)’ 1538 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, | ^~~~~~~~ /usr/include/c++/9/bitset:1538:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/memory:81, from /opt/ros/noetic/include/g2o/core/robust_kernel.h:30, from /opt/ros/noetic/include/g2o/core/base_binary_edge.h:34, from /home/guo/g2o仿真/src/optimize.cc:7: /usr/include/c++/9/bits/shared_ptr.h:66:5: note: candidate: ‘template<class _Ch, class _Tr, class _Tp, __gnu_cxx::_Lock_policy _Lp> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__shared_ptr<_Tp, _Lp>&)’ 66 | operator<<(std::basic_ostream<_Ch, _Tr>& __os, | ^~~~~~~~ /usr/include/c++/9/bits/shared_ptr.h:66:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:79:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Resetiosflags)’ 79 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Resetiosflags __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:79:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:109:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setiosflags)’ 109 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setiosflags __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:109:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:143:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setbase)’ 143 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setbase __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:143:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:178:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setfill<_CharT>)’ 178 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setfill<_CharT> __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:178:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:208:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setprecision)’ 208 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setprecision __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:208:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:238:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setw)’ 238 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setw __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:238:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:311:5: note: candidate: ‘template<class _CharT, class _Traits, class _MoneyT> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Put_money<_MoneyT>)’ 311 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_money<_MoneyT> __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:311:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:363:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Put_time<_CharT>)’ 363 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_time<_CharT> __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:363:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/local/include/eigen3/Eigen/Core:269, from /home/guo/g2o仿真/src/optimize.cc:4: /usr/local/include/eigen3/Eigen/src/Core/IO.h:249:16: note: candidate: ‘template<class Derived> std::ostream& Eigen::operator<<(std::ostream&, const Eigen::DenseBase<Derived>&)’ 249 | std::ostream & operator << | ^~~~~~~~ /usr/local/include/eigen3/Eigen/src/Core/IO.h:249:16: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note:std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const Eigen::DenseBase<Derived>’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ /home/guo/g2o仿真/src/optimize.cc:77:38: error: ‘Matrix6d’ has not been declared 77 | edge->setInformation(Matrix6d::Identity() * 100000); | ^~~~~~~~ /home/guo/g2o仿真/src/optimize.cc:79:38: error: ‘Matrix6d’ has not been declared 79 | edge->setInformation(Matrix6d::Identity() * 0.001); | ^~~~~~~~ /home/guo/g2o仿真/src/optimize.cc: In member function ‘Eigen::Isometry3d INS::CalibrationError::Get() const’: /home/guo/g2o仿真/src/optimize.cc:101:48: error: cannot call member function ‘double INS::Deg2Rad(double) const’ without object 101 | calib.rotate(AngleAxisd(Deg2Rad(0.1), Vector3d::UnitZ())); // Example rotation error | ^ /home/guo/g2o仿真/src/optimize.cc: In function ‘void generateSimulatedTrajectory(std::vector<Eigen::Transform<double, 3, 1> >&, int)’: /home/guo/g2o仿真/src/optimize.cc:131:42: error: ‘double INS::Deg2Rad(double) const’ is private within this context 131 | double angleStep = INS().Deg2Rad(90.0); // 每个转角的角度 | ^ /home/guo/g2o仿真/src/optimize.cc:106:12: note: declared private here 106 | double Deg2Rad(double deg) const { | ^~~~~~~ /home/guo/g2o仿真/src/optimize.cc:146:56: error: ‘double INS::Deg2Rad(double) const’ is private within this context 146 | pose.rotate(AngleAxisd(INS().Deg2Rad(rand() % 2), Vector3d::UnitZ())); | ^ /home/guo/g2o仿真/src/optimize.cc:106:12: note: declared private here 106 | double Deg2Rad(double deg) const { | ^~~~~~~ make[2]: *** [CMakeFiles/g2o_demo.dir/build.make:76:CMakeFiles/g2o_demo.dir/optimize.cc.o] 错误 1 make[1]: *** [CMakeFiles/Makefile2:673:CMakeFiles/g2o_demo.dir/all] 错误 2 make: *** [Makefile:146:all] 错误 2 给出完整修改后代码
最新发布
08-03
<html>没有匹配ostream(即 ostream)和function-overload-set类型的实参的可行 operator<<。<br/>考虑的候选项:<br/>ostream::__ostream_type &operator<<(ostream::__ostream_type &(*__pf)(ostream::__ostream_type &)) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 ostream::__ostream_type &(*)(ostream::__ostream_type &)<br/>ostream::__ostream_type &operator<<(ostream::__ios_type &(*__pf)(ostream::__ios_type &)) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 ostream::__ios_type &(*)(ostream::__ios_type &)<br/>ostream::__ostream_type &operator<<(ios_base &(*__pf)(ios_base &)) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 ios_base &(*)(ios_base &)<br/>ostream::__ostream_type &operator<<(long __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 long<br/>ostream::__ostream_type &operator<<(unsigned long __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 unsigned long<br/>ostream::__ostream_type &operator<<(bool __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 bool<br/>ostream::__ostream_type &operator<<(short __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 short<br/>ostream::__ostream_type &operator<<(unsigned short __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参 count 的转换格式错误: 无法将function-overload-set转换为形参类型 unsigned short<br/>ostream::__ostream_type &operator<<(int __n) (class basic_ostream<char, char_traits<char>> 中)<br/>1st实参
07-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值