讀取檔案2+root畫圖
阿新 • • 發佈:2019-01-06
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<vector>
#include <TGraph.h>
using namespace std;
int test()
{
fstream f1("D:\\88.txt", ios::in);
if (!f1)
{
cout << "讀取錯誤";
return -1;
}
vector<float> *x=new vector<float>;
x->clear();
char dat_tmp_char[100];
while(!f1.eof())
{
f1>>dat_tmp_char;
x->push_back(atof(dat_tmp_char));
}
cout<<x->size()<<endl;
for (int j = 0; j<(int)x->size(); j++)
{
cout << (*x)[j];
}
TH2D *h=new TH2D("h","h",21,-15,15,21,-15,15);
for(int i=0;i<21;i++)
{
for(int j=0;j<21;j++)
{
h->SetBinContent(i+1,j+1,(*x)[j*21+i]);
}
}
h->Draw("colz");
h->Draw("SURF");
return 0;
分別畫出兩張圖,這是第一次自己用root畫出圖片,突然發現root其實很好玩的,以後還要努力學習,加強學習效率。
早日成為一名程式媛~~
#include<fstream>
#include<string>
#include<sstream>
#include<vector>
#include <TGraph.h>
using namespace std;
int test()
{
fstream f1("D:\\88.txt", ios::in);
if (!f1)
{
cout << "讀取錯誤";
return -1;
}
vector<float> *x=new vector<float>;
x->clear();
char dat_tmp_char[100];
while(!f1.eof())
{
f1>>dat_tmp_char;
x->push_back(atof(dat_tmp_char));
}
cout<<x->size()<<endl;
for (int j = 0; j<(int)x->size(); j++)
{
cout << (*x)[j];
}
TH2D *h=new TH2D("h","h",21,-15,15,21,-15,15);
for(int i=0;i<21;i++)
{
for(int j=0;j<21;j++)
{
h->SetBinContent(i+1,j+1,(*x)[j*21+i]);
}
}
h->Draw("colz");
h->Draw("SURF");
return 0;
}
呼叫root後畫出兩張圖片
分別畫出兩張圖,這是第一次自己用root畫出圖片,突然發現root其實很好玩的,以後還要努力學習,加強學習效率。
早日成為一名程式媛~~