64,646
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int
main()
{
string str = "";
string tmp = "";
ifstream in("test.txt");
while(getline(in, str))
{
cout<<str.length()<<" "<<str<<endl;
for(int i = 0; i < str.length(); i++)
{
cout<<std::hex<<(int)str[i]<<" ";
tmp.append(&str[i]);
}
cout<<endl<<tmp.length()<<"----"<<tmp<<"----"<<endl;
tmp = "";
}
in.close();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string str = "";
string tmp = "";
ifstream in("test.txt");
while(getline(in, str))
{
cout<<str.length()<<" "<<str<<endl;
for(int i = 0; i < str.length(); i++)
{
cout<<std::hex<<(int)str[i]<<" ";
tmp.append(&str[i], 1); // 添加一个字符(默认是添加字符串的)
}
cout<<std::dec; // 返回到十进制输出
//cout<<endl<<endl;
cout<<endl<<tmp.length()<<"----"<<tmp<<"----"<<endl<<endl;
tmp = "";
}
in.close();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int
main()
{
string str = "";
string tmp = "";
ifstream in("F:\\11.txt");
char buf[2] = {0};
while(getline(in, str))
{
cout<<str.length()<<" "<<str<<endl;
for(int i = 0; i < str.length(); i++)
{
cout<<std::hex<<(int)str[i]<<" ";
buf[0] = str[i];
tmp.append(buf);
}
cout<<endl<<tmp.length()<<"----"<<tmp<<"----"<<endl;
tmp = "";
}
in.close();
return 0;
}