2012-01-15 114 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(); 

我忘了补充一点,在第一时间周围。

相关问题