#include<iostream>
#include<fstream>
using namespace std;
int main()
{
//从文件读数据
ifstream file("C:\\Users\\28901\\Desktop\\测试.txt");
char c[1024];
string tab,cod;
while(file.getline(c,sizeof(c)))
{
string str(c);
int pos=str.find(',');
string txt=str.substr(pos+1);
if(txt=="发送指令")
{
tab=str.substr(6,5);
cod=str.substr(17,pos-17);
break;
}
}
cout<<tab<<' '<<cod<<endl;
int table=atoi(tab.c_str());//字符串转int
int code=atoi(cod.c_str());
cout<<table<<' '<<code;
//获取文件内容大小
// ifstream file("C:\\Users\\28901\\Desktop\\测试.txt");
// file.seekg(0,ios::end);
// streampos ps=file.tellg();
// cout<<ps;
return 0;
}
c++读取文件内容
最新推荐文章于 2023-08-02 21:00:08 发布