473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

what is wrong with this cerr useage?

I get compiler error
"cerr undeclared first use this function."
#define err_ret(e) cerr << e; return -1

....

err_ret("who ate my muffy?");

Aug 11 '05 #1
8 3527
* sa************@hotmail.com:

#define err_ret(e) cerr << e; return -1


It's a macro, that's mainly what's wrong.

You have not shown your incorrect usage of the abomination.

But that hardly matters.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 11 '05 #2
I did show it...
err_ret("who ate my muffy?");

macros are not always bad.
what alternative do you suggest?

Aug 11 '05 #3

sa************@hotmail.com wrote:
I get compiler error
"cerr undeclared first use this function."
#define err_ret(e) cerr << e; return -1

...

err_ret("who ate my muffy?");


Wild guess: did you forget std:: before cerr?

Aug 11 '05 #4
I removed the macro, but I still get the same error with this code

cerr << "who ate my muffy?";

So the context of the macro or not is irrelevant, you completely missed
the point of my post.

Aug 11 '05 #5
yes, I just spotted this myself, it is a common error, so I detect a
hint of sarcasm in your post.

Aug 11 '05 #6
sa************@hotmail.com wrote:
I get compiler error
"cerr undeclared first use this function."
#define err_ret(e) cerr << e; return -1

...

err_ret("who ate my muffy?");


You need to have:

#include <iostream>
using std::cerr;

somewhere before the definition of your macro. However, I think the
real problem here is that you're using a macro when a function would do
just as well?

#define <iostream>
inline int err_ret(std::string e) /* or maybe char const *e */
{
std::cerr << e << std::endl;
return -1;
}

--
Mike Smith
Aug 11 '05 #7
* sa************@hotmail.com:
I removed the macro
Good.

, but I still get the same error with this code

cerr << "who ate my muffy?";
The compiler states that 'cerr' is undeclared.

It may be that you've forgotten to qualify the name, 'std::cerr', which is
most likely.

It may be that you've forgotten to include the relevant headers.

It may be that this is a spurious message due to earlier errors.

No way to tell when you don't post the code.

So the context of the macro or not is irrelevant,
Both the context of the macro definition and of the macro usage are
relevant.

And the problem with your output statement is somewhere in the context.

Which you haven't shown.

you completely missed the point of my post.


Nope.

Perhaps you've learned that macros are evil and context is important.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 11 '05 #8
Thanks.

Aug 11 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: learningGuy | last post by:
Can someone tell me what is wrong with this simple code? I get an exception every time at the myFile.Open() line. I have included the code that I think is needed to for you to answer this below:...
16
by: Quick Function | last post by:
What does it mean: int (*a);
7
by: Aguilar, James | last post by:
Hello all, To begin, yes, this -is- a homework assignment. However, it is for my Algorithms class, and my instructor has given us explicit permission to use "expert" groups like newsgroups, so...
2
by: Agoston Bejo | last post by:
Hi, how can one redirect std::cerr into a file? Specifically, if I have an ofstream object, is there something I can do to make "cerr << ..." calls write into that particular ofstream object? ...
1
by: Gurikar | last post by:
How to redirect information to file usinf cerr or clog. Regards
1
by: Scott | last post by:
Hello, I am not entirely clear on the difference between cerr and clog. When it is more appropriate to use one versus the other? I am coding a simple C++ application that will issue error and...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
3
by: Lambda | last post by:
I'd like to load a text file to memory. The code is like: void load_dict() { static const string DICT("D:\\README.txt"); ifstream dict(DICT.c_str(), std::ios::in); if (!dict) {
6
by: bbmmzz | last post by:
Here is my program: int main() { int ival; while(cin >ival, !cin.eof()) { if(cin.bad()) return 0; if(cin.fail())
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.