這本書提醒多次,是c++不是c。核心在於高級抽象。
0.一些概念//Pre
a.表達式與運算符
類型的表示的是一種數據結構以及對此數據結構的合理操作。運算符的操作取決於它的操作數類型。
內建類型:int...,拓展:std::ostream
(std::cout<<"This is a project:became a cpp master less than one month")<<std::endl //——std::endl 是個manipulator,控制cout)
b作用域(::作用域運算符)
名稱空間:在名稱空間中定義了所有名稱
花括號:
#include <iostream>
int main(){
std::cout << "This is a project:became a cpp master less than one month" << std::endl;
getchar();
return 0;
}
1.string
a.input
string 類型 用string name來聲明一個string 變量
(變量是具有名稱的對象,對象是在計算機中具有類型的內存空間)
#include <iostream>
#include <string>
using namespace std;
int main(){
cout << "This is a project:became a cpp master less than one month" << endl;
cout << "type in your name:\n";
string name;
cin >> name;
cout << "nice to meet you! Mr." << name<<"!";
getchar();
getchar();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main(){
cout << "This is a project:became a cpp master less than one month" << endl;
cout << "type in your name:\n";
string name;
cin >> name;
const string greeting = " hello," + name + "! ";
const string spaces(greeting.size(),' ');
const string secondline = "*" + spaces + "*";
const string firstline(secondline.size(), '*');
//cout << "nice to meet you! Mr." << name<<"!";
cout << firstline << endl;
cout << secondline << endl;
cout << '*'<<greeting<<'*' << endl;
cout << secondline << endl;
cout << firstline << endl;
getchar();
getchar();
return 0;
}