HackingC++ 机翻阅读记录 Chapter2-Input&Output

个人笔记向+google机翻(机翻确实很多细节描述不清,看不懂记得参考原文)
原文参见:https://hackingcpp.com/cpp/be...

Input&Output

1.Command Line Arguments 命令行参数

  • What &Why
  • How to Access in C++
int main (int const argc, char const* argv/*a pointer to a constant char*/) {
  • Argument Conversion
  • Conversion to std::string, int, …
 auto word  = string(argv[1]);
 int  times = atoi(argv[2]);
  • String → Number Conversion Functions

HackingC++ 机翻阅读记录 Chapter2-Input&Output_第1张图片

2.File Input&Output 文件输入输出

  • Write Text File
  • Read Text File
#include 
std::ofstream os {"squares.txt"};
os << xxxxx ; 
std::ifstream is {"squares.tst"};
is >> xxxxx ; 
  • Open/Close Files
 os.open("squares.txt");
 os.close("squares.txt");
  • File Open Modes

HackingC++ 机翻阅读记录 Chapter2-Input&Output_第2张图片

3.Stream Input&Output 流输入输出

  • Example: Point Coordinate I/O

4.Recover From Input Error 从输入错误中恢复

你可能感兴趣的:(c++)