ansi-C++ compiler test

Am about to get serious about studying and learning C++, and the C++ Language FAQ under the heading Information on this web page provides a test to check if my compiler recognizes ANSI-C++ features. I copied and pasted their example to Code::Blocks and it came up with these errors in the terminal...

2: using: not found
3: Syntax error: newline unexpected

Here is the code....

#include <iostream>
using namespace std;
template <class T>
bool ansisupported (T x) { return true; }

int main() {
if (ansisupported(0)) cout << "ANSI OK";
return 0;
}

Because Code::Blocks is an up to date IDE (I thought) (v8.02), shouldn't it be able to handle ANSI-C++ ?

Is there an error in the code, or is Code::Blocks not able to deal with the ANSI standard?

Thank you,
Bob
Be sure that you're using the C++ compiler and not the C one
Under settings compiler, it shows gnu gcc. Everywhere I look it says C/C++. Do you know where to set the mode to C++ if possible?
When you create a new project, you can choose between C and C++.
By the way, the current version of Code::Blocks is 10.05, which comes with a truly up-to-date compiler.
You got me good - can't find anywhere to designate the project as C++.
Ubuntu still has their most recent v as 8.02 in synaptic.
Just thought I'd run the quick test, but find that maybe IDE's require a learning curve as well, so I guess I'll do some more studying.
Thanks for your help, Athar.
You want to use GNU g++ not gcc. gcc is the C compiler, g++ is the C++ compiler.

Also, the error 'newline expected' is because you didn't include a newline at the end of your code. Put one after the very last bracket at the bottom of the file.

If you use g++ and have a newline at the end (if it doesn't, not a big deal though. g++ will treat it as a warning not an error) it will work.

Edit: Sorry, it says 'newline Unexpected' not expected... I would figure that is from trying to use gcc to compile... Though like I said, you'll get a warning if you don't have a newline at the EOF.

Worst comes to worst, you can just forget compiling from within the IDE, and do it from CL... i.e.
g++ -O3 -Wall -o ansi-test ansi-test.cpp
Last edited on
Ok, I have g++ installed according to synaptic, but it's not showing up in Code::Blocks. I'm trying to figure out how to get it installed.
Thanks folks for the homework :) I'll get back to you tomorrow after I get some studying done. Will give the terminal a go, also. Lots say to get used to g++ from the terminal, so I might as well dive in and get it down.
Good night
When you create a new project, select Console Application, then the following dialog should appear:
http://94.23.22.190/etc/cbcsele.png

To update Code::Blocks to the current version, run these commands in the terminal to add the two repo keys:
wget -q http://apt.wxwidgets.org/key.asc -O- | sudo apt-key add -
wget -q http://lgp203.free.fr/public.key -O- | sudo apt-key add -

Then add these two strings to the software sources:
deb http://apt.wxwidgets.org/ jaunty-wx main
deb http://lgp203.free.fr/ubuntu/ intrepid universe


and run the update manager.
You could also give Eclipse a try. I know for fact that it works well. You can create a C++ specific project, or C. Also comes in several other languages. Make sure to install the C++ version of Eclipse.
Am going to mark this question solved for now and come back to it later after I've got a better understanding of the tools for compiling.
Twud be simple if not for 1st day experience in C++ exposure, but by saving the file with .cpp extension forces Code::Blocks to compile in g++.
hahahaha :) m learning,eh?
Topic archived. No new replies allowed.