2011-03-07 2 views
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). 
+0

사용중인 입력의 예를 인용 해 주시겠습니까? –

+0

사용중인 입력은 다음과 같습니다. 03062011 1030 2.5 치과 의사 청소 Joshua 5552492131 – Joshua

+0

나는 작동 할 수 있습니다. 방금 int 변수를 double 값으로 변경했습니다. – Joshua

답변

1

당신은 4294967295 (AN unsigned int에서) 2147483647 또는 (signed int에) 당신이 될 것 저장할 수있는 '가장 큰'전화 번호로 10 자리 전화 번호를 저장하기 위해 int을 사용할 수 없습니다. 이들 중 어느 것도 거주 지역의 전화 번호를 503, 541 또는 971으로 저장하기에 충분하지 않습니다. Strings are probably best for storing phone numbers은 체코 공화국이나 아메리칸 사모아 등에서 전화 번호를 처리하기 위해 확장됩니다.

나는 수학, 과학 데이터 또는 물리 시뮬레이션 이외의 다른 것을 저장하기 위해 double을 사용하는 것에 대해서도 경계합니다. 이 점에 대해 double을 사용하는 대부분의 응용 프로그램은 대부분이 문제에서 벗어날 수 있지만, double은 바운드를 바깥쪽으로 약간 밀 때까지 정확히 데이터를 저장합니다. 데이터가 실제로 거의 저장됩니다.

+0

확인. 이제 파일을 읽으려고 할 때 날짜를 "5903ED4803062011"로 출력하고 날짜를 문자열 변수로 저장할 때 그걸 출력합니다. 왜 이렇게하고 어떻게 해결할 수 있습니까? – Joshua

+0

신경 쓰지 마라. – Joshua

+0

@ Joshua, thanks; 결국 문제를 어떻게 해결했는지 궁금합니다. :) – sarnold