Accelerated C++ day1

这本书提醒多次,是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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值