Page 1 of 1
C++ Skeleton
Posted: Sat Jun 15, 2002 5:54 pm
by rickyok
I usualy used this on BC 3.1 Windows
[cpp]
#include <iostream.h>
void main() {
int a;
cout << "Hello World!";
cin >> a;
}[/cpp]
But I try this at linux (because acm compile it at linux right?)
But it didn't work
Why?
Can some one give me the skeleton that I can used on linux
Thank you

Posted: Sat Jun 15, 2002 9:12 pm
by arnsfelt
Your code is not ansi c++
Try this instead
[cpp]
#include <iostream>
using namespace std;
int main() {
int a;
cout << "Hello World!";
cin >> a;
return 0;
}
[/cpp]
Posted: Sun Jun 16, 2002 8:03 am
by junjieliang
Can anyone tell me what the "using namespace std;" is for?
"using namespace std;"
Posted: Sun Jun 16, 2002 9:08 am
by Ming Han
I am also wondering what using namespace std; if for.
Can somebody please explain?
Thank You
namespace
Posted: Sun Jun 16, 2002 10:19 am
by Juergen Werner
With the ANSI C++ standard, the concept of namespaces was introduced. Roughly speaking, global identifiers can belong to a certain namespace, so you can have different global functions/variables with the same identifier, but within different namespaces (this is rather needed when working on a project with several developers, for acm problems there's no need to define your own namespaces). When "using namespace MySpace", you can directly use the identifiers from MySpace, otherwise you'd have to address them like "MySpace::Variable1".
According to the ANSI C++ standard, all elements of the C++ Library are defined in the namespace std. So when using these function, you either got to refer to that namespace via "using namespace std" or put the namespace in front of each element you're using like "std::cout << std::endl;".
Some C++ Compilers are now refering to the namespace std on default (like rickyoks "BC 3.1 Windows") where you can just use the functions without doing "using namespace std" by yourself, with other compilers, you got do one of the above mentioned methods to address the C++ Library functions correcty (I guess that's the correct way according to the standard, but since most times you're using std anyway, there's no need to state that in some compilers explicitely).
Well, you should be able to read more about namespaces in any decent C++ reference.
Posted: Sun Jun 16, 2002 5:49 pm
by rickyok
I've tried that arnsfelt give. I compiled it with GCC on mandrake 8.2 But it still didn't work.... gee i wonder whyy..
And what is synonim on ANSI C with this code
gotoxy(int x , int y);
clrscr();
Thank you
Posted: Sun Jun 16, 2002 7:51 pm
by Adrian Kuegel
gcc is for C only, not for C++. You have to use g++ to compile it.
Posted: Tue Nov 05, 2002 6:50 am
by zorbathut
C++ has no equivalents to gotoxy() or clrscr(). In fact, C doesn't either, technically, those functions are compiler-specific.
Now, as for compiler-specific, if you're on Linux check out the ncurses library. If you're going for Win32, start with looking up AllocConsole(). If you're on anything else, you might be able to use ANSI escape/color codes.