我使用的每一行都出现错误<<

发布于 2024-12-27 00:01:14 字数 1609 浏览 2 评论 0 原文

错误 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);
};

error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : >could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from >'std::string' c:\documents and settings\rcs\my documents\visual studio 2010\projects...

the Code is :

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫腻 2025-01-03 00:01:14
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();相同:它是文件您想要关闭,而不是表示其文件名的字符串。

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

skedar is a std::string, that (apparently) represents a path. file is an ofstream. If you want to write to that stream, you can't skedar << "whatever";, you need to output to the ofstream:

file << foo << "\n";

Same for skedar.close();: it's the file you want to close, not the string that represents its filename.

黯然 2025-01-03 00:01:14

您已经使用了 << skedar 上的运算符,它是一个字符串。字符串没有 <<操作员。您可能打算使用这样的内容:

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

我还注意到您有:

skedar.close();

而不是这个:

file.close();

我第一次忘记添加它。

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:

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

I also noticed that you had:

skedar.close();

Instead of this:

file.close();

I forgot to add that in the first time around.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文