I'm trying to create a sequential file but it doesn't seem to be working. Can anyone explain how to get this to work in 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
<< "Desc开发者_运维技巧ription, 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 << "? ";
}
}
And here is the output after I enter one line.
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).
You cannot use an int
to store 10-digit telephone numbers, as the 'largest' telephone number you could store would be (in signed int
) 2147483647
or (in an unsigned int
) 4294967295
. Neither of these are large enough to store a phone number from my home state with area codes 503
, 541
, or 971
. Strings are probably best for storing phone numbers, as they expand to handle phone numbers from Czech Republic or American Samoa and so forth.
I'm also leery of using double
for storing anything other than mathematics, scientific data or physics simulations. I may be a little paranoid about this, as most applications that use double
in this respect mostly get away with it, but double
s store data exactly until you slightly push outside their bounds, at which point they store data very approximately indeed.
精彩评论