zoukankan      html  css  js  c++  java
  • 【c++】读写txt

    #include<iostrea>

    #include<fstream>

    int main()

    {

      ofstream fout;// 创建一个ofstream对象

      fout.open("fileName.txt");//要写的txt 放到工程下

      fout<<123456<<endl;//像cout一样使用

      fout.close();//关闭

    ifstream ifs("outlog.txt");

    string str;

    FILE *input;
    char *str, line[4000];
    input = fopen("1", "rt");


    for (int i = 0; i < num; i++){
      str = fgets(line, 4000, input);
      if (str == NULL) break;
      str = strtok(str, " ");
      M[i*2]=atof(str);

    }

    二。数据长这样,要读入m1 m2

    13 34

    34 34

    98 98

    ifstream file1;
    file1.open("../data/1.txt");
    
    while(! file1.eof())
    {
       string s;
       getline(file,s);
       if(! s.empty)
       {
          stringstream ss;
          ss<<s;
          double m1;
          ss>>m1;
          ss>>m2;
        }   
    }

    另有

    http://blog.csdn.net/syunqiang/article/details/6425302

    #include <iostream>
    #include <sstream>
    #include <fstream>
    #include <string>
    int main(int args, char **argv)
    {
    std::ifstream fin("split.txt", std::ios::in);
    char line[1024]={0};
    std::string x = "";
    std::string y = "";
    std::string z = "";
    while(fin.getline(line, sizeof(line)))
    {
    std::stringstream word(line);
    word >> x;
    word >> y;
    word >> z;
    std::cout << "x: " << x << std::endl;
    std::cout << "y: " << y << std::endl;
    std::cout << "z: " << z << std::endl;
    }
    fin.clear();
    fin.close();
    return 0;
    }
  • 相关阅读:
    微信·小程序开发工具安装指南及注意事项
    测试
    PC上面的蓝牙的通信(C#)
    关于图片在div中居中问题
    JSONP---跨域请求问题
    关于position的用法
    APICloud自学笔记总结1
    前端html5
    关于图片自适应div大小问题
    亲身经历——大体量公司能为程序员的生涯带来什么帮助?
  • 原文地址:https://www.cnblogs.com/xy123001/p/5715183.html
Copyright © 2011-2022 走看看