与‘不匹配;操作员<<’;在‘;操作系统<<&引用;测试失败[“当操作系统是ostream”时]; > 我错误地使用包含< >当我需要包含 时,这主要是因为我将一些C风格代码与一个更大的C++程序集成在一起。
EndEdit 我在大学课堂上使用了一个简单的测试框架,但每当我使用提供的预处理器宏时,我都会遇到这两个错误。我自己扩展了宏,试图找出我做错了什么,但我被难倒了 错误: src/Url.cpp:在成员函数“bool Url::Test(std::ostream&)”中:与‘不匹配;操作员<<’;在‘;操作系统<<&引用;测试失败[“当操作系统是ostream”时]; > 我错误地使用包含< >当我需要包含 时,这主要是因为我将一些C风格代码与一个更大的C++程序集成在一起。,c++,C++,EndEdit 我在大学课堂上使用了一个简单的测试框架,但每当我使用提供的预处理器宏时,我都会遇到这两个错误。我自己扩展了宏,试图找出我做错了什么,但我被难倒了 错误: src/Url.cpp:在成员函数“bool Url::Test(std::ostream&)”中: src/Url.cpp:35:错误:“operatorstdio.h与C函数(如printf和scanf)不匹配 如果你想使用C++风格的I/O(流),你需要包含 IoSturi。< /P> VoILA!解决了问题。这就是我把C
src/Url.cpp:35:错误:“operator
stdio.h
与C函数(如printf
和scanf
)不匹配
如果你想使用C++风格的I/O(流),你需要包含<代码> IoSturi。< /P> VoILA!解决了问题。这就是我把C风格代码转换成C++的思想,而没有足够的思考。
#ifndef _URL_H
#define _URL_H
using namespace std;
class Url {
public:
Url();
Url(const Url& orig);
virtual ~Url();
bool Test(ostream & os);
bool setAsUrl(string relOrRegUrl, string baseUrl);
bool hasUrl();
string getUrl();
bool isHtml();
private:
string fullUrl;
bool html;
};
#endif /* _URL_H */
#include <string>
#include <cstring>
#include <stdio.h>
#include "UnitTest.h" //This contains the macro
#include "Url.h"
//using namespace std;
Url::Url() {
fullUrl = "NULL";
html = false;
}
Url::Url(const Url& orig) {
}
Url::~Url() {
}
bool Url::Test(ostream & os) {
bool success = true;
Url url= Url();
url.setAsUrl("http://www.cnn.com/news.jpg","http://www.cnn.com");
do {
if (!(url.isHtml() == false)) {
success = false; os << "Test Failed [" << __FILE__ << ", " << __LINE__ << "]" << endl; //line 35
}
}while(false);
// TEST(url.isHtml() == false); this is what gets expanded to the above
return success;
}
bool Url::setAsUrl(string relOrRegUrl, string baseUrl){
//Lots of code irrelevant to the question
}
bool Url::hasUrl(){
return fullUrl == "NULL";
}
string Url::getUrl(){
return fullUrl;
}
bool Url::isHtml(){
return html;
}
Url url = Url();
url.Test(std::cout);