对于在vs下写C++程序遇到:>......\picture_2_3.cpp(4): fatal error C1083: 无法打开包括文件:“iostream.h”: No such file or...

本文介绍了在Visual Studio环境下使用C++进行输入输出操作的方法。主要内容包括如何正确包含<iostream>头文件,以及如何使用std::cout进行输出,特别强调了在VS中endl的正确用法。

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

1.在vs下C++数输入输出函数的头文件为:

#include <iostream>     //注意这里没有.h作为头文件的标志。

引用输入输出时

std::cout<<image.size()<<'\t'<<image.type()<<'\n';
std::cout<<result.size()<<'\t'<<result.type()<<'\n';

加上域名!!!!!

还有一点vs下不直接识别endl自动换行标志。要转化为:

std::cout<<image.size()<<'\t'<<image.type()<<std::endl;
std::cout<<result.size()<<'\t'<<result.type()<<std::endl;

转载于:https://www.cnblogs.com/linmengran/p/5936481.html

#include "ros/ros.h" #include "ttauav_node/flightByOffset.h" #include "ttauav_node/flightByVel.h" #include "ttauav_node/gimbalControl.h" #include "ttauav_node/takeoffOrLanding.h" #include <ros/ros.h> #include <cstdlib> #include <stdio.h> #include <stdlib.h> //setlocale(LC_ALL, ""); //解决文字乱码 //******************需更改节点区域*************************// const char* wrap = "UAV_console"; //Get_Pictures.py IP地址 //opencv_sy1.py IP地址 //UAV_land_clap.py IP地址 // //**************************************************// std::string imagePath = "/root/picture/openmv/UAV_land.jpg"; std::string outputImagePath = "/root/picture/openmv/UAV_land.jpg"; //************************************获取角度高度等信息******************************************************** typedef struct { float gyro_roll; float gyro_pitch; float gyro_yaw; float roll; float pitch; float yaw; float height; } SensorData; void read_txt_file(SensorData* data) { const char* filepath = "/root/picture/openmv/UAV_data_angle_height.txt"; FILE* file = fopen(filepath, "r"); if (file == NULL) { ROS_INFO("无法打开无人机数据文件\n"); return; } fscanf(file, "陀螺仪:gyro_roll: %f, gyro_pitch: %f, gyro_yaw: %f\n", &data->gyro_roll, &data->gyro_pitch, &data->gyro_yaw); //ROS_INFO("陀螺仪:gyro_roll: %.6f, gyro_pitch: %.6f, gyro_yaw: %.6f\n", data->gyro_roll, data->gyro_pitch, data->gyro_yaw); fscanf(file, "角度:roll: %f, pitch: %f, yaw: %f\n", &data->roll, &data->pitch, &data->yaw); //ROS_INFO("角度:roll: %.6f, pitch: %.6f, yaw: %.6f\n", data->roll, data->pitch, data->yaw); fscanf(file, "高度:%f\n", &data->height); //ROS_INFO("高度:%.6f\n", data->height); fclose(file); } void yourCode() { // 在节点结束后执行的代码 // Your code here } // 启动ROS节点的函数 /*void startNode() { // 调用rosrun命令启动hhh节点 std::string cmd = "rosrun ttauav_node service_client 5 -35 1 "; system(cmd.c_str()); }*/ void UAV_delay_s(int i) //延时函数 i秒 { ros::Duration delay_1s(1.0); int a = 0; for(a = 0; a < i; a++) { ROS_INFO("倒计时:%d", i-a); delay_1s.sleep(); } } void UAV_delay_100ms(int i) //延时函数 i * 100 毫秒 { ros::Duration delay_100ms(0.1); int a = 0; i = i * 10; for(a = 0; a < i; a++) { //ROS_INFO("倒计时:%d", i-a); delay_100ms.sleep(); } } void UAV_control_init(int arg1, float arg2 = 0.0, float arg3 = 0.0, float arg4 = 0.0, float arg5 = 0.0) { ros::NodeHandle n; if (arg1 == 3) { ros::ServiceClient client = n.serviceClient<ttauav_node::flightByOffset>("flightByOffset"); ttauav_node::flightByOffset xiaoxi; xiaoxi.request.targetYaw = 90.2f; std::vector<float> offset; offset.push_back(arg2); offset.push_back(arg3); offset.push_back(arg4); xiaoxi.request.offset = offset; xiaoxi.request.yawThreshold = 1.0; xiaoxi.request.posThreshold = 0.5; bool tiaojian = client.call(xiaoxi); if (tiaojian) { ROS_INFO("success!!!!!"); ROS_INFO("result:%d", xiaoxi.response.ack); } else { ROS_INFO("failed!!!!!!"); } } else if (arg1 == 4) { ros::ServiceClient client = n.serviceClient<ttauav_node::flightByVel>("flightByVel"); ttauav_node::flightByVel xiaoxi; xiaoxi.request.targetYaw = arg5; ROS_INFO("偏航角调整: %f ", arg5); //实际距离误差调整 arg2 = arg2/2; arg3 = arg3/2; arg4 = arg4/2; xiaoxi.request.vel_n = arg2; xiaoxi.request.vel_e = arg3; xiaoxi.request.vel_d = arg4; xiaoxi.request.fly_time = 2000; bool tiaojian = client.call(xiaoxi); if (tiaojian) { ROS_INFO("水平控制:success!!!!!"); ROS_INFO("result:%d", xiaoxi.response.ack); //UAV_control(3); //给予3秒飞行反应时间 } } else if (arg1 == 5) { ros::ServiceClient client = n.serviceClient<ttauav_node::gimbalControl>("gimbalControl"); ttauav_node::gimbalControl xiaoxi; xiaoxi.request.pitch = arg2; bool tiaojian = client.call(xiaoxi); if (tiaojian) { ROS_INFO("云台控制 :success!!!!!"); ROS_INFO("result:%d", xiaoxi.response.ack); } else { ROS_INFO("云台控制 :failed!!!!!!"); } } ros::ServiceClient client = n.serviceClient<ttauav_node::takeoffOrLanding>("takeoffOrLanding"); ttauav_node::takeoffOrLanding xiaoxi; xiaoxi.request.takeoffOrLanding = arg1; bool tiaojian = client.call(xiaoxi); if (tiaojian) { ROS_INFO("success!!!!!"); ROS_INFO("result:%d", xiaoxi.response.ack); } else { ROS_INFO("failed!!!!!!"); } } } void picture(const std::string& customName) //调用摄像头拍一张照片 customName为名字 { std::string cmd = "rosrun UAV_console Get_Pictures.py _name:=" + customName; std::cout << "开始拍摄:" << cmd << std::endl; // 执行启动节点的命令(拍摄) system(cmd.c_str()); } int main(int argc, char *argv[]) { //先获取初始化角度 防止产生偏航 float UAV_yaw_init = get_yaw(); float UAV_yaw_real_time = UAV_yaw_init; //实时偏航角 float UAV_yaw_differ = UAV_yaw_init - UAV_yaw_real_time; //偏航角度差值 //飞行 ROS_INFO("起飞"); UAV_control(1); UAV_delay_s(2) //前飞x米 ROS_INFO("向前飞行 1m"); UAV_control(4, 1, 0, 0); UAV_delay_s(1); //左飞x米 ROS_INFO("向左飞行 1m"); UAV_control(4, 0, 1, 0); UAV_delay_s(1); //后飞x米 ROS_INFO("向后飞行 1m"); UAV_control(4, -1, 0, 0); UAV_delay_s(1); //右飞x米 ROS_INFO("向右飞行 1m"); UAV_control(4, 0, -1, 0); UAV_delay_s(1); ROS_INFO("云台置低"); UAV_control(5, -125, 1); UAV_delay_s(1); std::string pictureName = "UAV_land"; Scanning_picture(pictureName); UAV_delay_s(2); ROS_INFO("开始降落调试!!!***\n"); picture("UAV_land"); //获取中心坐标 cv::Point center = calculateImageCenter(imagePath, outputImagePath); float x_target = center.x; float y_target = center.y; ROS_INFO("中心坐标:%f, %f", x_target, y_target); UAV_delay_s(2); return 0; } 检查错误
06-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值