C++Primer 习题3.39-3.45
#include<iostream>
#include<string>
using namespace std;
int main()
{
const string str1{ "woshinibaba" };
const string str2{ "Woyeshinibaba" };
if (str1 != str2)
cout << "字符串不相等" << endl;
else
cout << "字符串相等" << endl;
char cst1[]{ 'w','s','n','b','b','\0' };
char cst2[]{ 'w','s','y','n','b','b','\0' };
if(strcmp(cst1,cst2))
cout << "C字符串不相等" << endl;
else
cout << "C字符串相等" << endl;
return 0;
}
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str1[]{ "wozhendeshinibaba" },
str2[]{ "我真的是你爸爸" };
char cst[18 + 15 - 1];
strcpy(cst, str1);
strcat(cst, str2);
for (auto a : cst)
cout << a;
return 0;
}
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int a[]{ 1,2,3,4,5,6,7,8,9,0 };
vector<int>va;
for (int i : a)
va.push_back(i);
for (int i : va)
cout << i << " ";
return 0;
}
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int>va{ 1,2,3,4,5,6,7,8,9,0 };
int a[10];
for (int i = 0; i < va.size(); i++)
a[i] = va[i];
for (int i : a)
cout << i << " ";
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int a[2][10]{ { 0,1,2,3,4,5,6,7,8,9 } ,{9,8,7,6,5,4,3,2,1,0} };
for (auto &p : a)
{
for (auto q : p)
cout << q << " ";
cout << endl;
}
cout << endl;
for (auto p = a; p != a + 2; p++)
{
for (auto q = *p; q != *p + 10; q++)
cout << *q << " ";
cout << endl;
}
cout << endl;
for (int p = 0; p < 2; p++)
{
for (int q = 0; q < 10; q++)
cout << a[p][q] << " ";
cout << endl;
}
cout << endl;
using intarray = int[10];
for (intarray *p = a; p != a + 2; ++p)
{
for (int *q = *p; q != *p + 10; q++)
cout << *q << " ";
cout << endl;
}
return 0;
}