- 此类换行错误,删除反斜杠
1
2warning: backslash and newline separated by
space int colAndrowArray[3][3]= \\后面的空格,就不会有waring了。 两种换行方式 添加
\或者 双引号""1
2
3
4
5cout << "Hello \
World" << endl;
cout << "Hello "
"World" << endl;++startValue 优于startValue++。
trueis 1 andfalseis 0stringvsstring.h一般来说,.h后缀都是c的头文件,与其相对应的不加.h的都是c++的头文件,比如#include <iostream.h>和#include <iostream>,前者是c的头文件,后者是c++的头文件,也就是c++没有.h的扩展名,一般后者都是前者的升级版本。 在c++标准化的过程中,为了表示头文件来源于c,有时也在前面加上c,比如cmath就来源于math.h但是string和string.h没有这样的关系,string.h是c处理c字符串的函数库,而string是c++的字符串类的头文件,二者没有任何关系。string也不是string.h的升级版strcpy(s1, s2);:复制字符串 s2 到字符串 s1。.c_str:c_str()方法是返回一个C语言字符串的指针常量(即可读不可改变),内容与调用此方法的原字符串相同。即通过c_str()方法,补充C中没有string类型的问题,,通过STRING类对象的成员函数c_str()把string对象转换为c中字符串的样式。 e.g.1
2
3char schar[5]={'\0'};
string cpstr= ("1234");
strcpy(schar,cpstr.c_str);枚举变量初始化也用
int(但实际上还是数字,输入的时候还是使用数字)注意上述 输入0代表Sunday,详见程序清单6.51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16int main()
{
enum DaysOfWeek
{
Sunday = 0,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
};
int dayInput = Sunday;
cin >> dayInput;
/*enter a number for a day (Sunday=0)*/
}vscode in wsl2 error: premission denied.
solution:note that: for local@host, myuser --> local; /path/to/folder is the path of the folder, local@host: ~/workfolder, /path/to/folder --> ~/workfolder. e.g.1
sudo chown -R myuser /path/to/folder
sudo chown -R local ~/workfolder主函数的两个子函数之间不会传递变量,e.g.:
上述程序运行出错,显示第二个1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16int main()
{
int numBer=0;
cin >> numBer;
if (numBer==1)
{
int num2=0;
cin >> num2;
}
int num3=0;
cin >> num3;
if (num3==12)
{
cout << num3 + num2 << endl;
}
}if函数中变量num2未定义,因为num2是在第一个if子函数中,不会作用到第二个中。使用
break退出当前循环;使用return退出当前函数模块。while(Integer)的循环,如果Integer 的值为-1,这个while 循环会执行吗? 理想情况下,while 循环表达式应为布尔值true 或false,否则这样解读:零表示false,非零表示true。由于−1 不是零,因此该while 条件为true,循环将执行。如果希望仅当Integer 为正数时才执行循环,可编写表达式while(Integer>0)。这种规则适用于所有的条件语句和循环。