#include<fstream>
#include<iostream>
using namespace std;
int main()
{
ofstream out("D://wang//test.txt");//写数据到指定目标文件夹,这个文件夹里可以没有test.txt文件,
if(out.is_open())
{
out<<"this is a line.\n";
out<<"This is another lien.\n";
out.close();
}
//从test.txt中读取数据
char buffer[256];
ifstream in("D://wang//test.txt");
if (!in.is_open())
{
cout<<"Error opening file";
}
while (!in.eof())
{
in.getline(buffer,100);
cout<<buffer<<endl;
}
return 0;
实际应用
SmoothPath(std::vector<geometry_msgs::PoseStamped> &total_plan)
{
ofstream out1("/home/viewbot/wanglinearV5.txt",ios::app);
int total_plan_size = total_plan.size();
double sum_x,sum_y;
int d,window_0,window_1;
for (int i = 0; i <= total_plan_size; i++)
{
do