我正在寫一個矢量陣列使用ofstream文件,但是某些值不獲取寫入,IE:問題與fstream的
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
char * hold = new char [100];
vector<double> fx(2049);
ifstream inputFile;
ofstream myFile;
inputFile.open("data.txt");
myFile.open("test.txt");
for (int c=0; c<2049; c++){
inputFile.getline(hold, 100);
fx[c] = atof(hold);
}
for (int c=0; c<2049; c++){
myFile << fx[c] << "\n";
}
}
在FX,下半場是所有等於0(FX [1024]至fx [0] = 0)。但是,在test.txt中,這些0值都不存在,因此應用回車符。有什麼想法嗎? 謝謝! (這些問題的格式化的新...任何提示,使這更容易理解)將不勝感激。
注:我意識到這個程序是相當多餘的。實際的程序有更多的功能,這只是一個工作不正確的領域。
我們可以看到'input()'? – chris 2013-03-26 00:39:52
我無法在您發佈的代碼中發現任何問題。也許更多的代碼會有幫助? :o – 2013-03-26 00:42:46
我加入了我用作fx [c]的輸入。 – 2013-03-26 00:47:03