64,652
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream inOut( "123.txt", ios_base::in|ios_base::app );
int cnt=0;
char ch;
inOut.seekg(0);
while ( inOut.get( ch ) )
{
cout.put( ch );
cnt++;
if ( ch == '\n' )
{
// 标记当前位置
ios::pos_type mark = inOut.tellg();
inOut << cnt << ' ';
inOut.seekg( mark ); // 恢复位置
}
}
inOut.clear();
inOut << cnt << endl;
cout << "[ " << cnt << " ]\n";
return 0;
}
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream inOut( "123.txt", ios_base::in|ios_base::app );// 以app方式打开,已开 始文件流指针指向文件末尾
int cnt=0;
char ch;
inOut.seekg(0); // 把文件流指针指向文件开始的地方
while ( inOut.get( ch ) )
{
cout.put( ch );
cnt++;
if ( ch == '\n' )
{
// 标记当前位置
ios::pos_type mark = inOut.tellg();
inOut.seekg(ios::end); // 把文件流指针指向文件末尾
inOut << cnt << ' ';
inOut.seekg( mark ); // 恢复位置
}
}
inOut.clear();
inOut << cnt << endl;
cout << "[ " << cnt << " ]\n";
return 0;
}
inOut.seekg(ios::end);
的,