zoukankan      html  css  js  c++  java
  • 08 IO库

     1 #include<iostream>
     2 #include<vector>
     3 #include<string>
     4 #include<fstream>
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     ifstream in("test.txt");
    10     if (!in)
    11     {
    12         cerr << "打开文件失败" << endl;
    13         exit(0);
    14     }
    15 
    16     vector<string> vec;
    17     string str;
    18     in >> str;
    19     while (getline(in, str))
    20         vec.push_back(str);
    21 
    22     for (auto c : vec)
    23         cout << c << endl;
    24     return 0;
    25 }
    #include<iostream>
    #include<vector>
    #include<string>
    #include<fstream>
    using namespace std;
    
    int main()
    {
        ifstream in("test.txt");
        if (!in)
        {
            cerr << "打开文件失败" << endl;
            exit(0);
        }
    
        vector<string> vec;
        string str;
        in >> str;
        while (getline(in, str))
            vec.push_back(str);
    
        for (auto c : vec)
            cout << c << endl;
        return 0;
    }

    test.txt文件内容:

    输出结果:

  • 相关阅读:
    TSQL语句
    约束
    数据库创建
    递归
    函数
    结构体
    集合
    jquery中的select
    正则表达式
    多表单提交
  • 原文地址:https://www.cnblogs.com/sunbines/p/9404246.html
Copyright © 2011-2022 走看看