我使用的每一行都出现错误<<
错误 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);
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
skedar
是一个std::string
,它(显然)代表一个路径。file
是一个ofstream
。如果您想写入该流,则无法 skedar << “whatever”;,您需要输出到ofstream
:与
skedar.close();
相同:它是文件您想要关闭,而不是表示其文件名的字符串。skedar
is astd::string
, that (apparently) represents a path.file
is anofstream
. If you want to write to that stream, you can'tskedar << "whatever";
, you need to output to theofstream
:Same for
skedar.close();
: it's the file you want to close, not the string that represents its filename.您已经使用了 << skedar 上的运算符,它是一个字符串。字符串没有 <<操作员。您可能打算使用这样的内容:
我还注意到您有:
而不是这个:
我第一次忘记添加它。
You've used the << operator on skedar, which is a string. Strings don't have an << operator. You probably meant to use something like this:
I also noticed that you had:
Instead of this:
I forgot to add that in the first time around.