Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <iostream>
- #include<fstream>
- #include <string>
- #include <vector>
- using namespace std;
- //float tabela[];
- int vel = 0;
- vector<string> strings;
- vector< vector<float> > podatki((100), vector<float>(100));
- void preberi(){
- ifstream input("test.csv");
- if (input.is_open()) {
- while (!input.eof()) {
- string ena;
- string s;
- int dolz = 0;
- //getline(input, ena); //read number
- //data = atoi(ena.c_str()); //convert to integer
- int vrsta = 0;
- while (getline(input, s, ';')) {
- //cout << s << endl;
- dolz++;
- strings.push_back(s);
- string sst = "";
- float fst = 0;
- int stolp = 0;
- //cout << s.length() << endl;
- cout << s[4] << endl;
- for (int i = 0; i < s.length(); i++) {
- if (s[i] == ','|| i== s.length() ) {
- fst = strtof(sst.c_str(), NULL);
- sst.clear();
- podatki[vrsta][stolp] = fst;
- cout << fst << "::" << podatki[vrsta][stolp] << " ";
- stolp++;
- }
- else {
- sst += s[i];
- }
- }
- fst = strtof(sst.c_str(), NULL);
- sst.clear();
- podatki[vrsta][stolp] = fst;
- cout << fst << "::" << podatki[vrsta][stolp] << " ";
- vrsta++;
- cout << endl;
- }
- cout << endl;
- vel = dolz/2+1;
- dolz = 0;
- //cout << strings[0][0] << endl;
- }
- }
- }
- void sestej() {
- vector< vector<float> > resitev((vel), vector<float>(vel));
- for (int i = 0; i < vel ; i++) {
- for (int j = 0; j < vel ; j++) {
- if(j%2!=1){
- resitev[i][j] = atof(&(const char)strings[i][j]) +atof(&(const char)strings[i + vel ][j]);
- cout << atof(&(const char)strings[i][j]) << "+" << atof(&(const char)strings[i + vel][j]) << "=";
- cout << atof(&(const char)strings[i][j]) + atof(&(const char)strings[i + vel][j]) << " ";
- }
- }
- cout << endl;
- }
- cout << endl; cout << endl;
- for (int i = 0; i < vel; i++) {
- for (int j = 0; j < vel; j++) {
- cout << (resitev[i][j ]) <<" ";
- }
- cout << endl;
- }
- }
- int main( int argc, char** argv) {
- if (argc == 3) {
- if (string(argv[1]) == "i") {
- printf("Int\n");
- preberi();
- sestej();
- }
- else if (string(argv[1]) == "f") {
- printf("Float\n");
- }
- else {
- printf("error\n");
- }
- for (int i = 0; i < argc; ++i) {
- std::cout <<i<<" "<< argv[i] << std::endl;
- }
- }
- else {
- printf("Premalo/Prevec parametrov....Pravilna uporab...\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement