错误C2784:'std :: basic_ostream< _Elem,_Traits> & std :: operator<<(std :: basic_ostream< _Elem,_Traits>&,const std :: basic_string< _Elem,_Traits,_Alloc>&)':>无法推断'std的模板参数:: basic_ostream< _Elem,_Traits> &安培;”来自>'std :: string'c:\ documents and settings \ rcs \ my documents \ 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);
};
答案 0 :(得分:1)
string skedar=foo;
ofstream file;
file.open(skedar, ios::app);
skedar<<foo+"\n";
skedar
是std::string
,(显然)代表路径。 file
是ofstream
。如果您要写入该流,则无法skedar << "whatever";
,您需要输出到ofstream
:
file << foo << "\n";
skedar.close();
相同:它是您要关闭的文件,而不是代表其文件名的字符串。
答案 1 :(得分:0)
您已使用&lt;&lt; skedar上的运算符,这是一个字符串。字符串不具有&lt;&lt;&lt;运营商。你可能想要使用这样的东西:
file<<skedar<<mosha<<"\n"<<gjinia<<"\n"<<foo<<"\n";
我也注意到你有:
skedar.close();
而不是:
file.close();
我忘了在第一时间添加它。