65,210
社区成员
发帖
与我相关
我的任务
分享
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
ifstream in("in.txt",fstream::in);
if(!in)
{
cerr<<"error"<<endl;
exit(1);
}
ofstream out("out.txt",fstream::out);
if(!out)
{
cerr<<"error"<<endl;
exit(1);
}
string line;
int line_no = 1;
while(getline(in, line))
{
out<<line_no<<" "<<line<<endl;
++line_no;
}
return 0;
}
int i=1;
string str;
ifstream ifile("c:\\ifile.txt"); //没有必要的异常检测,楼主自己写吧
ofstream ofile("c:\\ofile.txt");
while(getline(ifile,str))
{
ofile<<i++;
str=':'+str;
ofile<<str<<endl;
}
#include <iostream>
#include <sstream>
int main( int argc, char* argv )
{
std::string str = "646f20697420796f757273656c66";
char * dest = new char[str.size()];
for(int i = 0; i < str.size() / 2; ++i)
{
std::stringstream ss;
ss<<std::hex<<str.substr(i * 2, 2);
int x;
ss>>x;
dest[i] = x;
}
dest[str.size()/2] = 0;
std::cout<<dest<<std::endl;
delete [] dest;
std::system("pause");
}