0

次の演習を行っています。

ここに画像の説明を入力

私のコード:

#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    ifstream inFile;
    ofstream outFile;

    double currentSalary, increaseRate, updatedSalary;
    string firstName, lastName;

    inFile.open ("Data.txt");
    outFile.open("Output.dat");
    outFile << fixed << showpoint << setprecision(2);
    inFile >> lastName >> firstName;
    inFile >> currentSalary >> increaseRate;
    updatedSalary = currentSalary * (1 + increaseRate / 100);
    outFile << firstName << " " << lastName<< " " << updatedSalary << endl;
    inFile >> lastName >> firstName;
    inFile >> currentSalary >> increaseRate;
    updatedSalary = currentSalary * (1 + increaseRate / 100);

    outFile << firstName << " " << lastName<< " " << updatedSalary << endl;
    inFile >> lastName >> firstName;
    inFile >> currentSalary >> increaseRate;
    updatedSalary = currentSalary * (1 + increaseRate / 100);
    outFile << firstName << " " << lastName<< " " << updatedSalary << endl;

    system("PAUSE");
    return 0;
}

しかし、MS VSでデバッグすると、「続行するには何かキーを押してください...」と表示されます。

Data.txt ファイルはどこに追加すればよいですか?

4

2 に答える 2

3

画面に何も出力しないことを考えると、それだけが表示されてもまったく驚かないでしょう。

もし私があなたなら、Output.datファイルを調べて、何かが書き込まれているかどうかを確認します。

そのファイルに何も表示されない場合は、実行しているディレクトリにファイルがないことが原因である可能性がありData.txtます。VS では、これは通常、ソリューション ディレクトリ内のどこかのbinordebugディレクトリの下にあります。

system("cd");コードの先頭に配置して実行すると、どのディレクトリにあるかを確認できます。

于 2011-02-10T02:41:08.937 に答える
1

バイナリ ファイルを実行するのと同じディレクトリに Data.txt を配置するか、Data.txt の絶対パスを のようinFile.open ("C:\Documents\Data.txt")に配置する必要があります。そうしないと、決して見つかりません。

于 2011-02-10T02:44:08.447 に答える