Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int a,b,nbr=0,nbus;
float c,d,e;
vector<int> nl;
vector<int> nr;
vector<float> R;
vector<float> X;
vector<float> Bc;
complex<float>* Z=NULL;
complex<float>* y=NULL;
vector<vector<complex<float>>> ybus;
// First, get the number of line
ifstream mydata("load flow.txt");
string t3;
nbr=0;
while ( !mydata.eof())
{
while(getline(mydata, t3, '\n'))
++nbr;
}mydata.close();
// then read and get all the data in power flow data.txt
ifstream input ("load flow.txt");
for(int w=0;w<nbr;++w)
{
input >> a >>b >> c >>d >> e;
nl.push_back(a);
nr.push_back(b);
R.push_back(c);
X.push_back(d);
Bc.push_back(e);
cout<< a <<'\t' << b <<'\t'<< c <<'\t'<< d <<'\t'<< e<<'\t' <<endl;
complex <double> Z( c , d );
cout << "Z = " << Z << endl;
complex <double> y=1./Z;
cout<<y<<endl;
}mydata.close();
return 0;
}
my data is:
1 2 0.02 0.06 0.03
1 4 0.08 0.24 0.025
2 4 0.06 0.24 0.020
2 3 0.06 0.18 0.020
3 4 0.04 0.12 0.010
3 5 0.01 0.03 0.015
4 5 0.08 0.24 0.025