0
您好im學習c + +和我想知道如何我可以調用將寫入文件的函數。在該功能中,它將調用其他功能並打印輸出。我會怎麼做?如何調用函數,將寫入文件,並在該函數內調用其他函數
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void buildArray(float arrayScores[], int numOfScores);
void printOutArray(float arrayScores[], int numOfScores);
void writeToFile(float arrayScores[], int numOfScores);
int main(){
int numOfScores;
cout << "Enter the number of scores: "
cin >> numOfScores;
float *arrayScores = nullptr;
arrayScores = new float [numOfScores];
writeToFile(arrayScores, numOfScores);
delete [] arrayScores;
}
void buildArray(float arrayScores[], int numOfScores){
float score = 0;
for (int i=0; i<numOfScores; i++){
cout << "Enter the score: ";
cin >> score;
arrayScores[i] = score;
}
void printOutArray(float arrayScores[], int numOfScores){
int Items = numOfScores;
for (int i = 0; i<numOfScores; i++){
float grade = arrayScores[i];
cout << "Score number " << i+1 << ": " << arrayScores[i] << endl;
}
}
void writeToFile(arrayScores[], int numOfScores){
ofstream outfile;
outfile.open("Scores.txt");
outfile << buildArray(arrayScores,numOfScores);
outfile << printOutArray(arrayScores,numOfScores);
outfile.close();
}
'functionThatCallsOtherFunctionsInOrderToPrintToAFile();' - 但是你應該考慮一個更短,更具體的域名。 – StoryTeller
如果你使用新的,請正確使用它。你錯過了刪除。 – deviantfan
那麼除非你詢問構建錯誤,那麼請向我們展示*構建*的代碼。我建議你花些時間[閱讀如何提出好問題](http://stackoverflow.com/help/how-to-ask),並學習如何創建[最小,完整和可驗證示例]( http://stackoverflow.com/help/mcve)。 –