You are right laserlight. Sorry for the Croatian language. I will post English version now. I don't know what you mean by formatting of code because all of the "layout" was done by my editor i didn't touch a thing. I will put all of the code in functions later.
Dwks thank you. That helped a lot. But still while printing values of paths vector i get some memory junk in between my real values. Like this:
Code:
12 14
15 17 PATH 1
987 234
23 45
3.60739e-313 4.95672e-270
1.54972e-312 12
14 15
17 987
234 23 SOME MEMORY JUNK AND REPEATED VALUES FROM PATH 1
12 14
15 17
987 234
23 45
1 2
65 34
56 34 PATH 2
12 78
23 987
I'll post new code with English and deleted unnecessary parts:
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
class Coord { //values of coordinates (x,y)
public:
double xt;
double yt;
Coord(){};
Coord(double x, double y) : xt(x), yt(y) {};
};
typedef vector<Coord>Dots; //collection of coordinates for one path (one line in txt file is one path)
typedef vector<Dots>Paths; //collection of all paths
int main(int argc, char* argv[])
{
Paths trajectories;
Dots pairs;
int i,j;
if (argc == 2) {
ifstream dat (argv[1]);
if (!dat) {
cerr << "Given file cannot be opened "<< argv[1]<<endl;
}
while (!dat.eof()) {
string tmp;
double x,y;
getline(dat, tmp);
stringstream stmp(tmp);
int p=-1;
int &pp = p;
while (stmp >> x >> y) {
p++;
cout <<"counter pp="<<pp<<"\n"<<"number x "<<x<<" number y "<<y<<endl;
pairs.push_back(Coord(x,y));
cout <<"number x inside vector "<<pairs[pp].xt<<" number y inside vector "<<pairs[pp].yt<<endl;
// the lines for printing are just for testing because i had some problems here
}
trajectories.push_back(pairs);
}
}
else if (argc < 2) {
cout << "Error while running program" <<endl;
cout << "Usage: eg_decomposition <file_name>" <<endl;
}
else {
cerr << "Too much parameters" << endl;
exit (1);
}
// printing of all paths
for(i=0; i < trajectories.size(); i++) {
for (j=0; j < pairs.size(); j++)
cout << '\t' << trajectories[i][j].xt <<' '<<trajectories[i][j].yt << endl;
}
return 0;
}