个人笔记向+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
    image.png

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

  • Write Text File
  • Read Text File

    #include <fstream>
    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
    image.png

3.Stream Input&Output 流输入输出

  • Example: Point Coordinate I/O

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


ysysys
10 声望1 粉丝