I am trying to install MinGW so that I can use Eclipse to compile C++ source code. I download MinGW from here and install it. When I try comping it says "error: 'printf' was not declared in this scope"
is there a way I can attach a screen shot?
I am trying to install MinGW so that I can use Eclipse to compile C++ source code. I download MinGW from here and install it. When I try comping it says "error: 'printf' was not declared in this scope"
is there a way I can attach a screen shot?
Last edited by c_weed; 09-10-2010 at 02:20 PM.
c_weed,
The error means mingw is probably properly installed. That's a compilation error. Meaning it's your code that needs to be fixed.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
I currently don't have access to the file I was using, I'll get back to you on Monday.
Code:#include <iostream> using namespace std; int main() { printf("hello world!"); return 0; }
You are mixing C and C++ there. iostream is a strict C++ header, while printf is a C function (you can use it but you would have to include cstdio instead of iostream). Here are the tutorials for C++ provided on this site: Cprogramming.com - Programming Tutorials: C++ Made Easy and C Made Easy
They should set you off nicely on your way to c++ programming.
When I compile using gcc.exe it gives me about 7 lines of errors. Is there a way I can insert an image of a screen shot?
Last edited by c_weed; 09-15-2010 at 12:35 AM. Reason: added second sentence
No need. I think I know the problem. You should be compiling with g++ -- gcc will come up with errors every time. GCC as an acronym is the GNU Compiler Collection, but gcc the program is the C compiler; g++ is the C++ compiler.
Also, don't write stuff like this anymore. The printf function is not in iostream, but in cstdio. That was your earlier problem, provided that you used the right compiler....Code:#include <iostream> using namespace std; int main() { printf("hello world!"); return 0; }
Last edited by whiteflags; 09-15-2010 at 12:11 PM.
Yes, it has, by inheriting stdio.h and calling it cstdio. Like I said, printf is in the cstdio header.
That used to be the case, for the most part, but now there have been changes that make the two more incompatible. For instance,I thought printf was part of the c language and that c++ inherited all of c's functions?is nowCode:#include <stdio.h>. Even if you get it to work, writing new code that uses older C functions is generally discouraged, AFAIK. If you're going to write C++, using iostream's cin and cout, with the << and >> operators. If you're going to write C, then you use printf, scanf, etc..Code:#include <cstdio>
Not to mention that the C99 standard has features that are not included in C++. So worst case you wont even be able to compile the C code because it uses features in the newer standard.