hi so i need to fill an 2D array of dummy values like x with values form txt file, the "x" are there to fill in empty cols if file.txt has little or no data my file.txt looks like this
1 23 3 42 5 63 4 . 5
-2 1 43 95 55 5 43 2 -6
. 2 3 -4 5 43 -4 4 35
82 61 3 5 -5 65 . 2 6
my c++ looks like this
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int main(){
ifstream file;
ofstream newfile;
string filename;
string text;
const int n = 10;
char x = 'x';
double A[n][n];
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
A[i][j] = x;
cout << A[i][j];
}
}
do{
cout << "Podaj nazwe pliku(wraz z rozszerzeniem): ";
cin >> filename;
file.open(filename.c_str());
}while (!file.is_open());
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (!file.eof()){
getline(file, text);
A[i][j] = stod(text, 0);
}else{
break;
}
}
}
file.close();
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cout << A[i][j];
}
cout << endl;
}
}
when i print out this array i get output like 127.77098e-3184 i can't copy my input because it's not printing right now i don't know why
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…