C++怎么得出文件中某一行的长度,就举例第一行
2个回答
展开全部
//读取文本文件的每一行,得到字符串长度
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string str;
cout<<"input file:";
cin>>str;
ifstream in(str.c_str());
if(!in)
{
cout<<"open file error";
exit(0);
}
while(!in.eof())
{
getline(in,str);
cout<<str<<endl<<"size:"<<str.size()<<endl;
}
return 0;
}
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string str;
cout<<"input file:";
cin>>str;
ifstream in(str.c_str());
if(!in)
{
cout<<"open file error";
exit(0);
}
while(!in.eof())
{
getline(in,str);
cout<<str<<endl<<"size:"<<str.size()<<endl;
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询