qt开发环境 - c++字符串操作
2017-08-13 17:31
489 查看
#include <QCoreApplication> #include <iostream> #include <string> #include <cstring> using namespace std; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); //c++的字符串定义 string s1; cout << '[' << s1 << ']'<< endl; string s2("ayumi hamasaki"); cout << '[' << s2 << ']'<< endl; //c字符串和c++字符串,c++支持把c风格的字符串隐式转换为c++风格 string s3 = "字面值mai kuraki";//字面值隐式转换 cout << '[' << s3 << ']'<< endl; char const* ps = "字符指针mai kuraki"; cout << '[' << ps << ']'<< endl; s3 = ps; cout << '[' << s3 << ']'<< endl; char sa[] = "字符数组mai kuraki"; cout << '[' << sa << ']'<< endl; cout << strlen(s3.c_str()) << endl;//字符串成员函数,可以获得c的首地址 //字符串的赋值 对应c strcpy string s4("ayumi hamasaki……"); s3 = s4; cout << '[' << s3 << ']'<< endl; //字符串的拼接 对应c strcat string s5("I love "); s3 = s5 + s4; cout << '[' << s3 << ']'<< endl; //字符串复合赋值 s5 += s3 += s4;//右结合 cout << '[' << s5 << ']'<< endl; //字符串的比较 ASCII 长度 strcmp string s6 = "abcd", s7 = "abCd", s8 = "abcde"; cout << (s6 > s7) << endl; cout << (s6 > s8) << endl; s6 = "擎天柱"; s7 = "威震天"; s8 = "大黄蜂";//按照编码 cout << (s6 > s7) << endl; cout << (s6 > s8) << endl; //下标访问 cout << s4[2] << endl; //字符串的大小 不包括 /0 cout << s5.size() << endl; cout << s8.length() << endl; //判断字符串是否为空 cout << s8.empty() << endl;//0 s8.clear(); cout << s8.empty() << endl;//1 return a.exec(); }
相关文章推荐
- qt开发环境 - c++函数换名,extern 'C',缺省参数,内联
- ubuntu14.04 qt4 C++开发环境搭建
- CrossApp开发时, 存放在Resource下的文件在android环境下使用assets/..路径 使用C++的文件操作类如(fopen、ifstream等)找不到的问题
- 构建C/C++开发环境(包括gtk/qt等开发库)(适合ubuntu9.10)
- qt-eclipse-c++环境配置(图形界面开发)
- C/C++开发环境(GTK/GNOME/Qt/KDE)
- qt-eclipse-c++环境配置(图形界面开发)
- C/C++ 开发环境配置(GTK/GNOME/Qt/KDE)
- 构建 C++ 开发环境包括 gtk、qt 等开发库
- 【C/C++开发】字符串操作
- qt开发环境 - c++之无名名字空间,名字空间嵌套邻近原则(内藏外),名字空间别名
- qt开发环境 - c++之结构,联合,枚举
- C/C++开发环境(GTK/GNOME/Qt/KDE)
- TreeFrog Framework开发环境搭建 (C++ web framework, based on Qt)
- qt开发环境 - c++之输入,输出,名字空间定义,名字空间指令,名字空间声明
- qt-eclipse-c++环境配置(图形界面开发)
- Qt/C++ 开发Android平台《林中伊人》消球小游戏全记录2——Qt on Android开发环境的搭建
- 【C/C++开发】字符串操作
- TreeFrog Framework(C++ web framework, based on Qt)开发环境搭建
- CC++初学者编程教程(10) 搭建Android java C/C++ NDK QTforAndroid 开发环境