tags:

views:

43

answers:

1

Edit: I incorrectly used #include <stdio.h> when I needed to include <iostream>. This happened mostly because I was integrating some C style code with a larger C++ program.

EndEdit

I'm using a simple test framework for my college class, but whenever I use the provided preprocessor macro I get these two errors. I've expanded the macro myself to try and figure out what I'm doing wrong, but I'm stumped.

errors:

src/Url.cpp: In member function ‘bool Url::Test(std::ostream&)’:

src/Url.cpp:35: error: no match for ‘operator<<’ in ‘os << "Test Failed ["’

src/Url.cpp:35: error: ‘endl’ was not declared in this scope

inc/Url.h

#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 */

src/Url.cpp

#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;
}

Sorry about the long line length, that's what the macro expands to. Oh, and if it helps, what's being passed into Test() is cout as in

Url url = Url();
url.Test(std::cout);

So, I'm stumped, and if this seems like a dumb question, sorry. I'm new to C++.

A: 

stdio.h is for C functions like printf and scanf.

If you want to use C++ style I/O (streams) you need to include iostream.

Pace
Voila! Fixed the problem. That's what I get for converting C-style code to C++, without thinking about it enough.
Trevor