私は C++ の初心者で、初めて getline() 関数を使用しようとしています。このコードを書いたところ、2 つのエラーが表示されました。
このコードは何をすることになっていますか? read.txt から 4 つの数値を読み取り、それを計算して平均を求め、出力を output.txt に書き込むことになっています。
4 つの数字 (read.txt 内) はすべて、次のように別々の行にあります。
6
12
15
19
コードは次のとおりです。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
ifstream readFile;
ofstream sendFile;
readFile.open ("read.txt");
sendFile.open ("output.txt");;
float mean;
int num, num2, num3, num4;
getline(readFile, num), getline(readFile, num2), getline(readFile, num3), getline(readFile, num4);
readFile >> num >> num2 >> num3 >> num4;
sendFile << "1. The mean of " << num << ", " << num2 << ", " << num3 << ", and " << num4 << "is " << (num + num2 + num3 + num4) / 4;
readFile.close();
sendFile.close();
system ("PAUSE") ;
return 0;
}
エラーは次のとおりです: IntelliSense: オーバーロードされた関数「getline」のインスタンスが引数リストと一致しません 20 IntelliSense: 関数呼び出しの引数が少なすぎます 20