g++ -g -o test test.cpp//生成带调试信息的可执行文件
gdb -tui//上面窗口是代码
C++读取txt文件(按行读取)
#include<iostream>
//#include<stdlib.h>
//#include <vector>
//#include <math.h>
#include<string>
#include <fstream>
#include <cassert>
//#include <cmath>
using namespace std;
void readTxt(string file)
{
ifstream infile;
infile.open(file.data()); //将文件流对象与文件连接起来
assert(infile.is_open()); //若失败,则输出错误消息,并终止程序运行
string s;
while(getline(infile,s))
{
cout<<s<<endl;
}
infile.close(); //关闭文件输入流
}
int main()
{
//string str="D:\\BITVehicle_Dataset\\label1.txt ";
//readTxt(str);
FILE *fin = fopen("/media/muphy/Elements/BITVehicle_Dataset/label1.txt", "r"); /*假设文件名为file.txt*/
int a[9850]={0};
int i;
for (i = 0; i < 9850; i++) {
fscanf(fin, "%d", &a[i]);
}
fclose(fin);
for(int i=0;i<9850;i++)
cout<<a[i]<<endl;
/*此时已经读取完毕,可以进行接下来的处理了*/
//system("pause");
return 0;
}
matlab生成label文件,并保存为txt文件
load('VehicleInfo.mat');
a=zeros(9850,1);
for i=1:9850
c=VehicleInfo(i).vehicles.category;
%d='Truck'
if (strcmp(c,'Bus')==1)
a(i)=1;
end
if (strcmp(c,'Microbus')==1)
a(i)=2;
end
if (strcmp(c,'Minivan')==1)
a(i)=3;
end
if (strcmp(c,'Sedan')==1)
a(i)=4;
end
if (strcmp(c,'SUV')==1)
a(i)=5;
end
if (strcmp(c,'Truck')==1)
a(i)=6;
end
end
save label.mat a;
save label.txt -ascii a;
fid=fopen('label1.txt','wt');
fprintf(fid,'%g\n',a);
fclose(fid);