2014-04-17 4 views
1

저는 C++을 아직도 배우고 있다고 말하고 싶습니다. 그래서 Structures에 관한 모듈로 시작했습니다. 그리고 모든 것을 이해하지 못하는 동안 다소 이상하다고 생각합니다. 컴파일러에서 계속해서 제공하는 오류는 다음과 같습니다.C++ 오류 - '.'앞에 예상되는 primary-expression이 있습니다. 토큰 | IN STRUCTURE

오류 : '.'앞에 예상 기본 표현식이 있습니다. 토큰 |

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

struct catalog 
{ 
    char title[50]; 
    char author[50]; 
    char publisher[30]; 
    int yearpublish; 
    double price; 
}; 

int main() 
{ 
    catalog book; 
    char again; 

    fstream fbook; 
    fbook.open("book.dat", ios::out | ios::binary); 

    do 
    { 
     //Read data about the book 
     cout << "Enter the following data about a book:\n"; 
     cout << "Title:"; 
     cin.getline (book.title,50); 
     cout << "Author:"; 
     cin.getline (book.author,50); 
     cout << "Publisher name:"; 
     cin.getline (book.publisher,30); 
     cout << "Year publish:"; 
     cin >> book.yearpublish; 
     cin.ignore(); 
     cout << "Price:"; 
     cin >> book.price; 
     cin.ignore(); 

     //write the contents to the binary file 
     fbook.write((char*)&catalog , sizeof(book)); 

     cout << "Do you want to enter another record?(Y/N)"; 
     cin >> again; 
     cin.ignore(); 
    } while (again == 'Y' || again == 'y'); 

    fbook.close(); 
    return 0; 
} 

제발 도와주세요.

+1

해야 무엇? – RichieHindle

답변

4

당신이

fbook.write((char*)&catalog , sizeof(book)); 

내가 생각이 라인에 여기서 뭐하는는 라인 오류를보고있다에

fbook.write((char*)&book , sizeof(book)); 
+0

정말 고마워요. 방금 내 문제를 해결했습니다. – user3544721

관련 문제