2

我正在尝试创建一个顺序文件,但它似乎不起作用。谁能解释如何让它在 MS Visual Studio 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 << "? ";
    }
}

这是我输入一行后的输出。

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

您不能使用 anint来存储 10 位电话号码,因为您可以存储的“最大”电话号码是 (in signed int)2147483647或 (in an unsigned int) 4294967295。这些都不够大,无法存储我家乡的电话号码,带有区号503541971字符串可能最适合存储电话号码,因为它们扩展到处理来自捷克共和国或美属萨摩亚等国的电话号码。

我也对double用于存储数学、科学数据或物理模拟以外的任何东西持怀疑态度。我可能对此有点偏执,因为double在这方面使用的大多数应用程序大多会侥幸成功,但会double精确存储数据,直到您稍微超出其界限,此时它们确实非常近似地存储数据。

于 2011-03-07T02:22:50.073 回答