2012-01-15 113 views
1

錯誤C2784:「的std :: basic_ostream < _Elem,_Traits> &的std ::操作< <(STD :: basic_ostream < _Elem,_Traits> &,常量性病: :basic_string < _Elem,_Traits,_Alloc> &)':>無法爲'std :: basic_ostream < _Elem,_Traits> &'從std :: string'c:\ documents和settings \ rcs \ my推導模板參數文件\ visual studio 2010 \ projects ...在每一行收到錯誤我已經使用<<

代碼是:

#include <iostream> 
#include <fstream> 
#include <sstream> 
#include <string> 
#include "Pacient.h" 

using namespace std; 

void ruajKartele(Pacient patient) 
{ 
    int mosha; 
    char gjinia; 
    string foo=patient.getEmer(); 
    string skedar=foo; 
    ofstream file; 
    file.open(skedar, ios::app); 
    skedar<<foo+"\n"; 
    mosha=patient.getMosha(); 
    gjinia=patient.getGjinia(); 
    foo=patient.getDiagnoza(); 
    skedar<<mosha<<"\n"<<gjinia<<"\n"<<foo<<"\n"; 
    foo=patient.getPrognoza(); 
    skedar<<foo+"\n"; 
    skedar<<"-----\n"; //5 
    skedar.close(); 
} 
int _tmain(int argc, _TCHAR* argv[]) 
{ 
    return 0; 
} 
//Pacient structure: 
    #include <string> 
class Pacient 
{ 
protected: 
    std::string emer; 
    int mosha; 
    char gjinia; 
    std::string diagnoza; 
    std::string prognoza; 

public: 
    Pacient(void); 
~Pacient(void); 
void setEmer(std::string); 
void setMosha (int); 
void setGjinia(char); 
void setDiagnoza(std::string); 
void setPrognoza(std::string); 
std::string getEmer(void); 
int getMosha(void); 
char getGjinia(void); 
std::string getDiagnoza(void); 
std::string getPrognoza(void); 
}; 

回答

1
string skedar=foo; 
ofstream file; 
file.open(skedar, ios::app); 
skedar<<foo+"\n"; 

​​是std::string,即(顯然)表示的路徑。 fileofstream。如果你想寫入該流,你不能skedar << "whatever";,你需要輸出到ofstream

file << foo << "\n"; 

同爲skedar.close();:它是文件要關閉,並不表示該字符串的文件名。

+0

我之前忘了提及skedar.close()。我現在添加它。爲你+1! :) – batbrat 2012-01-15 10:22:34

+0

非常感謝你!,我一直在與一些項目工作了很長時間,我的眼睛顯然已經失明! 我不能告訴你剛纔的幫助! – Vinset 2012-01-15 10:22:59

0

您已經在skedar上使用了< <運算符,它是一個字符串。字符串沒有< <運算符。你可能想用的是這樣的:

file<<skedar<<mosha<<"\n"<<gjinia<<"\n"<<foo<<"\n"; 

我還注意到,您有:

skedar.close(); 

取而代之的是:

file.close(); 

我忘了補充一點,在第一時間周圍。

相關問題