2017-05-05 10 views
0

D:\ Backup \ TuDien \ TestWrite.cpp [エラー]オペレータ< <(オペランドの種類は 'std :: fstream {別名:: basic_fstream}'と 'ワード')に一致しません'operator <<'に一致するものはありません(オペランドの種類は '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

答えて

関連する問題