2

シーケンシャルファイルを作成しようとしていますが、機能していないようです。これをMSVisualStudio 2010で機能させる方法を誰かが説明できますか?

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;

int main()
{
    ofstream outClientFile( "clients.dat", ios::out);

    if (!outClientFile)
    {
        cerr << "File could not be opened" << endl;
        exit(1);
    }

    cout << "Enter the Appointment Date, Time, Duration, Name," << endl
        << "Description, Contact Name, and Contact Number.\n? "; 

    int appDate, appTime, appContactNum;
    string appName, appDescription, appContactName;
    double appDuration;

    while ( cin >> appDate >> appTime >> appDuration >>
        appName >> appDescription >> appContactName >> appContactNum )
    {
        outClientFile << appDate << ' ' << appTime << ' ' << appDuration << ' ' << appName << ' ' << appDescription << ' ' << appContactName << ' ' << appContactNum << endl;
        cout << "? ";
    }
}

そして、これが私が1行入力した後の出力です。

Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
The program '[452] CSC275 Assignment 3.exe: Native' has exited with code 0 (0x0).
4

1 に答える 1

1

intを使用して10桁の電話番号を保存することはできません。これは、保存できる「最大の」電話番号が(in signed int2147483647または(in unsigned int)であるため4294967295です。これらはどちらも、私の自宅の州の電話番号を市外局番、、、またはで保存するのに十分な大きさではあり503ませ541971。文字列は、チェコ共和国や米領サモアなどの電話番号を処理するように拡張されるため、電話番号を格納するのにおそらく最適です。

doubleまた、数学、科学データ、物理シミュレーション以外のものを保存するために使用するのも嫌です。doubleこの点で使用するほとんどのアプリケーションはほとんどそれを回避するので、私はこれについて少し妄想するかもしれませんがdouble、境界を少し超えるまでデータを正確に保存します。その時点で、データはほぼ実際に保存されます。

于 2011-03-07T02:22:50.073 に答える