Accelerated C++ day1

来源:互联网 发布:网络舆情分析系统 编辑:程序博客网 时间:2024/03/29 01:43

这本书提醒多次,是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;
}

0 0
原创粉丝点击