#include
#include
#include
using namespace std;
QTextStream cin(stdin, QIODevice::ReadOnly);
QTextStream cout(stdout, QIODevice::WriteOnly);
void display_data(char *buff, size_t len)
{
for(size_t i = 0; i < len; ++i){
std::cout << hex << showbase << uppercasedigits
<< (unsigned)buff[i] << " ";
std::cout << endl;
}
}
int main()
{
std::cout << "char* :\n";
char *buff = "中文";
display_data(buff, strlen(buff));
std::cout << "wstring: \n";
wstring ws = L"中文";
display_data((char*)ws.data(), ws.length() * 2);
std::cout << "QString: \n";
QString qs = "中文";
display_data((char*)qs.data(), qs.length() * 2);
std::cout << "turn GB2312 to Unicode: \n";
//将每个Unicode 用QChar 表示
QString qs2 = QString::fromLocal8Bit("中文");
display_data((char*)qs2.data(), qs2.length() * 2);
}
标准库basic_string 类模版的构造函数:
template
, class Allocateor =
allocator
>
class basic_string
{
public:
//construct an empty string
explicit basic_string(cosnt Allocator &a = Allocator());
//construct a user-given string
basic_string(const charT *s, const Allocator &a = Allocator());
//set the string's length be n, if longer than n, only save n chars
basic_string(const charT * s, size_type n, const ALlocator &a = Allocator());
//copy n chars start at the str's pos
//if user not claim the n, default action is start from pos to the end
basic_string(const basic_string &str, size_type pos = 0,
size_type n = npos, const Allocator &a = Allocator());
};