I think your question is about c++ ... so it should be posted in c++ forum ... you'll get replies there.
nanosani
Unauthenticated Liar
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
I imagine it complains about these lines:
using std::cout;
using std::cin;
Why? try just "using std;" instead.ITYM
using namespace std;
Except in 'toy' programs, you really don't want to grab the whole namespace -- doesn't that kind of defeat the purpose of the namespace?
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Unless you HAVE TO use specific code, this works GR8!
:rolleyes:Program for more than a couple days before you start teaching.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
:rolleyes:Program for more than a couple days before you start teaching.
Hey now. Be nice.
If there's something wrong with what he's posted, wouldn't it be more helpful to point out what's the problem/.
alc6379
Cookie... That's it
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
Hey now. Be nice.
If there's something wrong with what he's posted, wouldn't it be more helpful to point out what's the problem/.
There is one function that should be avoided at all costs --gets. Millions of Google hits can tell you why. But I can provide links if you'd like. Any program that contains one of these constructs stinks of a C newbie:
void main()
gets(string);
fflush(stdin);
Unless you HAVE TO use specific code, this works GR8!
(Sorry if its a little to late!)
#include <stdio.h>
#include <string.h>
int main()
{
char name[50];
char item[50];
char exit[10];
printf("What is your name?\n\a");
gets(name);
printf("What is one thing you REALLY want?\n\a");
gets(item);
printf("Congratulations, %s! You just won %s!\nTo collect, please send 100$ to California.\n(Press enter to exit)",name,item);
gets(exit);
return 0;
}
The original code was C++, for which different methods are used for input and output. And this code uses the most dangerous function in the C standard library as an "improvement". And the last one also uses a reserved identifier -- the name of a standard library function.Besides, it works, doesn't it?
I know there is a better way to do it, but the way I described and compiled works.That is the most dangerous way to code: it "works". (By accident, not by design.)
It is never safe, but it "works".
Sometimes the only way to capture someone's attention is to be a little bit of an ass. Try not to take it personally. Try to take it as constructive criticism without wiggle room.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
instead of
gets(whatever string/char?);
What command should I use?
(I forgot to be specific in previous reply, and I already used my edit on it.)
Generally, fgets . But you will notice that this may leave an unwanted newline in the input string -- there are a number of ways to remove it .
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314