我正在尝试从输入文件中填充矢量矢量。
#include<fstream>
#include<vector>
#include<iostream>
using namespace std;
int main(){
ofstream inputFile;
inputFile.open("input.dat");
if(!inputFile){
cout << "Error in reading" << "input" << endl;
return 0;
}
vector<vector<double> > A;
double element;
vector<double> temp;
while(inputFile << element){
temp.push_back(element);
A.push_back(temp);
}
int len = A.size();
int i, j;
for(i=0; i<len; i++){
for(j=0; j<len; j++){
cout << A[i] <<"\n";
}
}
return 0;
}
我正在使用它作为测试文件,所以我正在尝试打印矩阵A.任何帮助都会非常感激。
test.cpp:33:9: error: no match for ‘operator<<’ (operand types are
‘std::ostream {aka std::basic_ostream<char>}’ and ‘std::vector<double>’)
cout << A[i] <<"\n";
答案 0 :(得分:0)
将while循环更改为:
while(inputFile >> element){
temp.push_back(element);
A.push_back(temp);
}
在嵌套for循环中执行cout<<A[i][j]<<endl;