1.打印数组:只有装字符串的char c[]数组可以打印,整型,字符串数组string s[],char*s[]都要用for循环打印
2.字符串数组:建议用string s[],不用char*[]
3 .#include <> 和 #include "" 都会在实现定义的位置查找文件...区别是若 #include "" 查找成功,则遮蔽 #include <> 所能找到的同名文件;否则再按照 #include <> 的方式查找文件...一般来说 #include <> 的查找位置是标准库头文件所在目录, #include "" 的查找位置是当前源文件所在目录
4.带参数的宏命令:#define area(x) x*x;则area(2+2)为8
5.断言:assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行。
例:fp = fopen( "noexitfile.txt", "r" );//以只读的方式打开一个文件,如果不存在就打开文件失败
assert( fp ); //所以这里出错
fclose( fp ); //程序永远都执行不到这里来
6.使用qt 教你如何用CodeBlocks+MinGW+Qt在windows下的安装及环境配置
7.对于char数组型变量,在非声明的时候进行赋值,不能直接赋值,比如:
char str[64];
str="abcdf";//对数组的不合法赋值,而且长度为6,和64不等
正确的做法为借助于strcpy函数,例如:
char str[64]';
strcpy(str,"abcde");
8.拷贝构造函数:https://www.runoob.com/cplusplus/cpp-copy-constructor.html
9.atoi():c的库函数<stdlib.h> int atoi(const char *str) 把参数 str 所指向的字符串转换为一个整数(类型为 int 型)。
10.strtok():c的库函数<string.h>: char *strtok(char *str, const char *delim) 分解字符串 str 为一组字符串,delim 为分隔符。
char str[80] = "This-is-me";
const char s[2] = "-";
char *token;
/* 获取第一个子字符串 */
token = strtok(str, s);
* 继续获取其他的子字符串 */
while( token != NULL ) {
printf( "%s\n", token );
token = strtok(NULL, s); }
11.字符串数组的转化:string[]转化为char*[]:
constr= str.c_str();
c= const_cast<char*>(constr);