Qt 与C11 对string 的处理

#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());
};

    
    
   
   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值