*C++学习错误记录:1.C++使用cout输出字符串,需要引入<string>头文件*
#include<iostream>
#include<string>
using namespace std;
//值传递
void swap1(int a,int b) {
int temp = a;
a = b;
b = temp;
}
//地址传递
void swap2(int *p1, int *p2) {
int temp = *p1;
*p1 = *p2;
*p2 = temp;
}
int main() {
//错误记录,输出字符串是要引入<string>头文件
int a = 10;
int b = 20;
string d = "32131";
//swap1(a, b);//值传递不会改变实参
swap2(&a, &b);//地址传递会改变实参
cout << "a=" << a <<d<< endl;
cout << "b=" << b << endl;
system("pause");
return 0;
}