Cześć, od dłuższego czasu męczę się z prostym zadaniem, a mianowicie, wczytywaniem i zapisywaniem danych do pliku csv. Próbowałem własnymi siłami to zrobić, ale nie udało mi się, więc spróbowałem pomóc sobie internetem. W internecie znalazłem następujący kod:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
struct Matrix
{
int k, w;
float **M;
};
Matrix ReadCSV(string fileName)
{
vector<vector<string>> content;
vector<string> row;
string line, word;
fstream file (fileName, ios::in);
if(file.is_open())
{
while(getline(file, line))
{
row.clear();
stringstream str(line);
while(getline(str, word, ','))
row.push_back(word);
content.push_back(row);
}
}
else
cout<<"Could not open the file\n";
for(int i=0;i<content.size();i++)
{
for(int j=0;j<content[i].size();j++)
{
cout<<content[i][j]<<" ";
}
cout<<"\n";
}
}
int main()
{
ReadCSV("a.csv");
return 0;
}
Jednak to również nie rozwiązało mojego problemu. Program zwraca komunikat "Could not open the file"
Proszę o pomoc, już któryś dzień siedzę nad tym problemem