traj_out variable ‘std:ofstream’ has initializer but incomplete type

博客指出在C++代码中,出现‘variable 'std:ofstream’ has initializer but incomplete type’或‘variable 'std:ifstream’ has initializer but incomplete type’错误,原因是未包含fstream头文件,强调包含该头文件对避免此类错误的重要性。

variable 'std:ofstream’ has initializer but incomplete type

或者是variable 'std:ifstream’ has initializer but incomplete type

其原因是因为没有包含fstream这个头文件。

Cpp代码

#include<fstream>  
#include<iostream>  
#include<string>   
using namespace std;  
int main()  
{  
fstream f("filename");  
f << 20;  
f.close();   
}   

上面这段代码如果没有那个就会有标题的错误。

#ifndef CTRL_FSM_PLANNING_H #define CTRL_FSM_PLANNING_H #include <cmath> #include <string> #include <ros/ros.h> #include <ros/callback_queue.h> #include <std_msgs/Bool.h> #include <std_msgs/Int32.h> #include <sensor_msgs/Imu.h> #include <nav_msgs/Odometry.h> #include <geometry_msgs/PoseArray.h> #include <geometry_msgs/PoseStamped.h> #include <mavros_msgs/State.h> #include <common/visual.hpp> #include <common/trajectory.hpp> #include <common/quat_euler_convert.hpp> #include <ctrl/motion_controller_separate.h> #include <common/traj_anal.hpp> #include <carstatemsgs/Polynome.h> class CtrlFSMPlanningDDR { public: // Constructor CtrlFSMPlanningDDR() = delete; CtrlFSMPlanningDDR(const ros::NodeHandle &nh, const ros::NodeHandle &pnh); CtrlFSMPlanningDDR(const CtrlFSMPlanningDDR &rhs) = delete; CtrlFSMPlanningDDR &operator=(const CtrlFSMPlanningDDR &rhs) = delete; CtrlFSMPlanningDDR(CtrlFSMPlanningDDR &&rhs) = delete; CtrlFSMPlanningDDR &operator=(CtrlFSMPlanningDDR &&rhs) = delete; virtual ~CtrlFSMPlanningDDR() {} private: // State Machine enum FSM_EXEC_STATE { INIT, HOVER, CMD_CTRL, WAIT }; FSM_EXEC_STATE exec_state_; std_msgs::Int32 exec_state_int_; float hover_yaw_; Eigen::Vector2f hover_pos_; bool have_odom_; bool have_traj_; bool new_hover_flag_; bool is_ground_; bool follow_traj_finished_; bool is_armed_; bool emergency_stop_flag_; // ROS NodeHandle ros::NodeHandle nh_; ros::NodeHandle pnh_; // ROS Subscribers ros::Subscriber odom_sub_; ros::Subscriber flight_status_sub_; ros::Subscriber mavros_state_sub_; ros::Subscriber plan_traj_sub_; ros::Subscriber goal_sub_; ros::Subscriber emergency_stop_sub_; // ROS Publishers ros::Publisher attitude_target_pub_; ros::Publisher follow_traj_finished_pub_; ros::Publisher ground_ctrl_fsm_pub_; ros::Publisher allow_plan_traj_pub_; // ROS Timers ros::Timer run_timer_; // ROS Topics std::string odometry_topic_; std::string attitude_target_topic_; std::string flight_status_topic_; std::string follow_traj_finished_topic_; std::string ground_ctrl_fsm_topic_; std::string mavros_state_topic_; std::string plan_traj_topic_; std::string goal_topic_; std::string allow_plan_traj_topic_; std::string emergency_stop_topic_; // Variables common::trajectory::CurEstimate<float> cur_estimate_; // Have been initialized to zero TrajAnal traj_; Trajectory<5, 2> minco_traj_; double traj_duration_; ros::Time start_time_; geometry_msgs::PoseStamped goal_; double goal_received_time_; bool allow_plan_traj_; int traj_id_; // PID Controller Parameters PIDParams position_pid_params_; PIDParams velocity_pid_params_; // Common Parameters CommonParams common_params_; // Thrust Parameters float thrust_return_; bool use_thrust_change_; // Visualizer the trajectory common::visual::TrajectoryVisualizer::Ptr traj_visualizer_; // Motion Controller MotionControllerSeparate::Ptr motion_controller_; // Functions void changeFSMExecState(FSM_EXEC_STATE new_state, string pos_call); void printFSMExecState(); // Callback functions void odomCallback(const nav_msgs::Odometry::ConstPtr &msg_ptr); void flightStatusCallback(const std_msgs::Bool::ConstPtr &msg_ptr); void mavrosStateCallback(const mavros_msgs::State::ConstPtr &msg_ptr); void planTrajCallback(const carstatemsgs::Polynome::ConstPtr &msg_ptr); void goalCallback(const geometry_msgs::PoseStamped::ConstPtr &msg_ptr); void emergencyStopCallback(const std_msgs::Bool::ConstPtr &msg_ptr); void runTimerCallback(const ros::TimerEvent &event); void publishAttitudeTarget(const std::pair<float, float> &desired_attitude, const float &feedforward_pitch_rate, const float &feedforward_yaw_rate); }; #endif // CTRL_FSM_PLANNING_H 注释上述代码
最新发布
09-20
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值