Accelerated C++ 学习笔记及题解----第一章
来源:互联网 发布:网络新词汇 编辑:程序博客网 时间:2024/05/21 09:12
字符的使用
本章的主要内容是基本的格式化的输入输出.
顺带介绍的是string变量的使用.
char以及wchar_t字符按类型
string类型及其基本使用方法,
标准输入输出符
变量的定义方式.
以下是题解:
1-6
#include <iostream>#include <string>int main() {std::cout << "What is your name? ";std::string name;std::cin >> name;std::cout << "Hello, " << name<< std::endl << "And what is yours? ";std::cin >> name;std::cout << "Hello, " << name<< "; nice to meet you too!" << std::endl;return 0;}
书中的代码:
加框:
// ask for a person's name, and generate a framed greeting#include <iostream>#include <string>int main() {std::cout << "Please enter your first name: ";std::string name;std::cin >> name;// build the message that we intend to writeconst std::string greeting = "Hello, " + name + "!";// build the second and fourth lines of the outputconst std::string spaces(greeting.size(), ' ');const std::string second = "* " + spaces + " *";// build the first and fifth lines of the outputconst std::string first(second.size(), '*');// write it allstd::cout << std::endl;std::cout << first << std::endl;std::cout << second << std::endl;std::cout << "* " << greeting << " *" << std::endl;std::cout << second << std::endl;std::cout << first << std::endl;return 0;}
0 0
- Accelerated C++ 学习笔记及题解----第一章
- Accelerated C++ 学习笔记及题解----第零章
- Accelerated C++ 学习笔记及题解----第二章
- Accelerated C++ 学习笔记及题解----第三章
- 《Accelerated C++》 笔记摘录
- Accelerated C++学习笔记1—<开始学习C++>
- 《Accelerated C++》前面部分笔记
- Accelerated C++学习笔记 Ch1
- Accelerated C++学习笔记 Ch2
- Accelerated C++学习笔记 Ch3
- Accelerated C++ 学习笔记1
- Accelerated C++ 学习笔记2
- Accelerated C++ 学习笔记3
- Accelerated C++学习笔记4
- 学习C++,第一本书《Accelerated C++》
- “Accelerated C++” 阅读笔记(一)
- “Accelerated C++” 阅读笔记(二)
- “Accelerated C++” 阅读笔记(三)
- 2014腾讯校园招聘实习笔试题目广州站
- java远程访问mysql数据库
- 从Hadoop框架与MapReduce模式中谈海量数据处理(含淘宝技术架构)
- C++开发者都应该使用的10个C++11特性
- 2014腾讯校园招聘实习笔试题目西安站
- Accelerated C++ 学习笔记及题解----第一章
- 汇编语言->Makefile
- What is a Full Stack developer?
- Excel的float转字符
- MIT算法导论第七讲学习笔记-哈希表(Hashing)
- servlet中ServletConfig实例
- IA__gdk_gc_new: assertion 'drawable != NULL' failed
- 处理linux服务器cpu的wa%值过高
- unity 跑酷游戏开发笔记(二)