文件读写

#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <cctype>
#include <initializer_list>
//#include <sstream.h>
//#include "Sales_item.h"
using namespace std;
//统计种类1的原子x大于0.45的每个时间步的个数
int main()
{
    ifstream fi;
    fi.open("atomacc.lammpstrj"); //用于读入数据的流
    ofstream fo;
    fo.open("result.txt"); //用于输出计量

    //if(fi.is_open()) cout<<"good\n";

    string temp;
    int i=0,n=0,type;
    int tempi;
    double x,y,z;
    vector<int> count;  //统计符合条件的个数
    while(!fi.eof())
    {
        if(n%14064==0)
        {
            i=n/14064;
            count.push_back(0);
            for(int i=0;i<9;i++) {
                getline(fi,temp); //跳过9行
                n++;
            }
            if(n>10) getline(fi,temp);
        }
        //cout<<i<<n<<endl;
        fi>>tempi>>type>>x>>y>>z; 
        n++;
        
        if(type==1 && x>0.45) 
        {
            count[i]++;
        }
    }
        cout<<i<<endl;

    for(i=0;i!=count.size();++i)
    {
        cout<<"Tiem step "<<i<<" count "<<count[i]<<endl;
        //cout<<count[i];
    }
    
    fi.close();
    fo.close();
    
    
    return 0;
}

 

posted on 2019-03-20 11:01  BabyStep  阅读(158)  评论(0编辑  收藏  举报

导航