2017-05-05 1 views
0

D : \ Backup \ TuDien \ TestWrite.cpp [ 오류] 오퍼레이터 타입이 'std :: fstream {aka std :: basic_fstream}'이고 '워드'입니다.'연산자 <<'에 일치하는 항목이 없습니다 (피연산자 유형이 'std :: fstream {일명 :: basic_fstream <char>}'이고 'Word'입니다)

이 문제를 해결하는 데 도움을주십시오. 고마워요!

#include <fstream> 
#include<stdio.h> 
#include<string.h> 
#include<ctype.h> 
#include<conio.h> 
#include<stdlib.h> 
using namespace std; 
struct Word 
{ 
char word[10]; 
char mean[20]; 
}; 
Word word; 
void writeDataToFile() 
{ 
std::fstream fileOutput("D:/data.txt", std::ios::out | std::ios::binary); 


if (fileOutput.fail()) 
{ 
    std::cout << "Cannot open file at " << "D:/data.txt" << std::endl; 
    return; 
} 

     Word a; 
     strcpy(a.mean,word.mean); 
     strcpy(a.word,word.word); 
     fileOutput << a << endl;  
} 

void readDataFromFile() 
{ 
std::ifstream fileInput("D:/data.txt"); 

if (fileInput.fail()) 
{ 
    std::cout << "Cannot open file at " << "D:/data.txt" << std::endl; 
    return; 
} 

while (!fileInput.eof()) 
{ 
    char line[255]; 
    fileInput.getline(line, 255); 
    std::cout << line << std::endl; 
} 
} 

int main() 
{ 
strcpy(word.word,"Apple"); 
strcpy(word.mean,"Trai tao"); 
writeDataToFile(); 
readDataFromFile(); 
return 0; 
} 
+0

오류는 매우 명확합니다. 'fileOutput << a << endl; '존재하지 않는 연산자를 사용하려고합니다. 그 운영자가 어떤 모습이어야 하는지를 알면서만 작성해야합니다. [연산자 오버로딩] (https://stackoverflow.com/questions/4421706/operator-overloading)을 참조하십시오. – WhozCraig

답변

관련 문제