如题,下面是代码,为什么打印出来tmp.length()不是我想要的长度?
C/C++ code #include <stdio.h>#include <stdlib.h>#include <iostream>#include <fstream>#include <string>
using
namespace std;intmain(){ 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<<"
"; tmp.append(&str); } cout<<endl<<tmp.length()<<"----"<<tmp<<"----"<<endl; tmp =
""; } in.close(); return
0;} |