I am trying to open a .mtx file and print the data out, mainly to see how the data is loaded. I want to use the data itself as soon I can load it all, but currently, it loads the first line only, and says it fails after that line.
Debug Assertion Failed! Program:..etc1 - Opening MTX FILE\Debug\Project1 - Opening MTS FILE.exe File:...(something) Line:3204 Expression: string subscript out of range
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
long int n = 0;
string line;
ifstream data("/Users/MYPC/Desktop/matrix.mtx");
if (data.is_open() == true)
cout << "File opened successfully" << endl;
while (n != sizeof(line))
{
getline(data, line);
while (n!=sizeof(data))
{
cout << line[n];
n++;
}
}
system("pause");
return 0;
}