我有4行3列如何打印二维对向量的值?
(0.165334,0) (0.166524,-0.0136064) (-0.144899,0.0207161)
(0.205171,0) (0.205084,-0.0139042) (-0.205263,0.0262445)
(0.216684,0) (0.215388,-0.0131107) (-0.193696,0.0251303)
(0.220137,0) (0.218849,-0.0135667) (-0.194153,0.025175)
我写了下面的代码打印的FFTfile
值的文本文件。该脚本不会引发任何错误,但不会打印值。任何想法什么是错的?
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <dirent.h>
#include <string>
#include <sstream>
using namespace std;
class Point
{
public:
double x;
double y;
friend istream& operator>>(istream& input, Point& p);
friend ostream& operator<<(istream& s, Point& p);
double getX(void);
double getY(void);
};
double Point::getX(void){
return x;
}
double Point::getY(void){
return y;
}
istream& operator>>(istream& input, Point& p)
{
char c;
input >> c; // Read open parenthesis
input >> p.x;
input >> c; // Read comma
input >> p.y;
input >> c; // Read closing parenthesis
return input;
};
ostream& operator<<(ostream& s, Point& p)
{
s << p.getX() << ", " << p.getY();
return s;
}
vector<vector<Point> > LoadFFT(string path){
string Filename;
vector<vector<Point> > matrix;
Filename.append(path);
Filename.append("....txt");
ifstream fileFFT(Filename.c_str());
string raw_text;
while(getline(fileFFT, raw_text)){
vector<Point> row;
istringstream(raw_text);
Point p;
while(raw_text >> p){
row.push_back(p);
}
matrix.push_back(row);
}
return(matrix);
}
int main(){
vector<vector<Point> > FFTfile=LoadFFT("...");
for (int i = 0; i < FFTfile.size(); i++)
{
for (int j = 0; j < FFTfile[i].size(); j++){
cout << FFTfile[i][j];
}
}
return(0);
}
你永远不会测试文件是否成功打开。你怎么能确定该文件实际打开? – Fureeish
我只是一个小菜人!用C/C++经验还不到一个月,你能帮上忙吗? – Spandy
你缺乏经验并不能让你受到不同的待遇。我建议检查文件打开是否成功。你有没有试过检查你的程序是否适用于它? – Fureeish