formatierte ausgabe einer matrix
-
Hallo,
ich schaffe es nicht eine formatierte ausgabe einer matrix hinzubekommen.
Mit formatiert meine ich das jede stell in der gleichen spalte ist.
bei mir sind die stellen so verrutscht...ich habe es so versucht:std::cout << "Matrix: " << std::endl; std::vector<double>::iterator iter; std::cout.setf(std::ios::floatfield); // scientific-Notation std::cout.setf(std::ios::adjustfield, std::ios::right); // rechtsbündig std::cout.setf(std::ios::showpoint); // Dezimalpunkt und abschliessende Nullen ausgeben std::cout.precision(5); for(int i = 0; i < 5; i++) { for(int j = 0; j < 5; j++) std::cout << std::setw(10) << std::setfill(' ') << matrix[j*5 + i] << " " ; std::cout << "" << std::endl; }ich würde es evtl. so wollen:
1.4444 9.993
0.0 -2.88743
-2.44 0.0oder auch so:
1.4444 9.99300
0.0000 -2.88743
-2.4400 0.00000aber lieber nummer eins

-
Check diz out: http://www.cplusplus.com/ref/iostream/iomanip/
Besonders:
setfill: Set fill character.
setprecision: Set decimal precision.
setw: Set field width.
-
eh....sowas hab ich schon ausgecheckt
Siehe code....es funktioniert aber eben net ganz bei mir ...:) Trotzdem danke