持续学习&持续更新中…
名称空间using namespace std;的解释
即使用std这个名称空间的意思。

#include <iostream>
int main(void) {
int n;
std::cin >> n;
std::cout << "hello, cpp" << n + 1 << std::endl;
return 0;
}
cin和cout
 

#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
cout << n << endl;
cout << "hello cpp\n";
return 0;
}

C++与C头文件的关系

C++特有的bool变量

C++特有的const定义常量

C++中的string类


C++的struct和C语言struct的区别

C++中的引用

使用引用:
#include <iostream>
using namespace std;
void func(int &a) {
a = 99;
}
int main(void) {
int n;
n = 1;
cout << n << endl;
func(n);
cout << n << endl;
return 0;
}
不使用引用:
#include <iostream>
using namespace std;
void func(int a) {
a = 99;
}
int main(void) {
int n;
n = 1;
cout << n << endl;
func(n);
cout << n << endl;
return 0;
}
C++中STL之动态数组vector的使用
    定义vector的方式一:
vector<int> v(10);
cout << v.size();
定义vector的方式二:
vector<int> v;
cout << v.size() << endl;
v.resize(10);
cout << v.size();
定义vector的方式三:
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
vector<int> v(10, 8);
for(vector<int>::iterator it = v.begin(); it != v.end(); it++) {
cout << *it << endl;
}
return 0;
}
vector的访问:
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
vector<int> v(10, 8);
for(int i = 0, length = v.size(); i < length; i++) {
cout << v[i] << endl;
}
return 0;
}

参考
柳婼: 从放弃C语言到使用C++刷算法的简明教程.
本文完,感谢您的关注支持!
|