September 22nd, 2003, 02:38 AM
I am also a C++ newbie. I am workin on C++ in Highschool and we use Turbo version 4.5 C++ Compiler. I have no idea where they found this at, or if it is a pay version. But I cant find a Turbo compiler like it. I have downloaded Dev C++ and almost gave up on it becuz I could not get my simple programs to work. Well I just got done reading the thread Help on Dev C++ and heard about this namesspace and std:: thingy. I did a lil search on the net and looked it up in my Reference book, but both answers were far over my head. I was wondering what it is, and why I have to use it in Dev when trying to use the cout command when I dont have to use it at school. Also wondering gerenal info on the whole library and if there is like a set of libraries all C++ programmers use, becuz our student helper creates his own little libraries for us to use at school. Any info is apperciated.
September 22nd, 2003, 03:00 AM
A namespace is a definition of code that is constant across most compilers, std being the standard template library, or the standard namespace. Most compilers use their own tweaked version of it by default which can be a pain when using multiple compilers if you don't know the little subtleties to them. To use this namespace you can either add the line "using namespace std" after your includes but before any other code or you can use "std::<function/class>()" for the specific instance you want to use it, for example if you wanted to use the stl version of cout, which usually isn't changed either way, you could use "std::cout << yourstuff;" instead of jus "cout << yourstuff;", I find strings are usually handled differently in the stl than microsoft's standard libraries, I've run into some differences in g++ as well. The big benefit to this is of course that if you work on many different platforms and compilers you can just add that line of code at the top and now you don't need to learn any compiler specific little tricks.
Reality is the one who has it wrong, not you
September 22nd, 2003, 03:58 AM
Thank you pecosian,
I got it to compile and run now, but it just flashes. Use the school compiler when we run the program it prints the output in a white box and just stay there until you close it. Using dev, a black bow blinks like my code is running, it prints the ouput, and then close in a sec. This is my exact code.
//Just a try
using namespace std;
cout<<"I see you"<<endl;
I dont know why it wont stay up there. I modified the examples dev gave me so they are no use. One of the examples they gave me uses a while loop, but I modified it so now it has become an infinate loop. I dont know what to do. Help!
September 22nd, 2003, 04:05 AM
yeah sometimes stuff like that happens...my Microsoft Visual C++ compiler did that. All you have to do is add something like this
You can use a using directive, or you can use using declarations....i used both, which is bad programming, but i just wanted to show you that there are multipule ways to do it Also, dont forget to return something!
using namespace std;
int main (void)
std::cout << "Hello" << std::endl;
std::cout << "I see you" << std::endl;
//to make sure window stays open type...
std::cout << "Press any key to end this program" << std::endl;
std::cin >> x; //window stays open until you enter something...
About your problem with the while loop...i dont exactly understand what you did, but if you dont want it to run forever, then make it something like this:
^^i think that will compile, to lazy and stupid to enter it into my compiler...
int main (void)
cout << "I HATE LOOPS, AND THIS WILL ONLY LOOP 10 TIMES";
BY THE WAY---> namespaces in C++ are something completly different than what is being explained here. you call a namespace if you want to save a variables name so when another program run on top of your program, the variable names dont get all screwed up. When you are programming a big application you whould use namespaces so 20 different programs dont all have the same variable names. Anyways, someone correct me if i am wrong, because i am sure i said something wrong. Instead of calling this C++ Namespace, you should have titled this C++ Using Namespace Directives and Declarations to better describe the content of this post. Anyways, just trying to help you out
Support your right to arm bears.
^^This was the first video game which i played on an old win3.1 box
September 26th, 2003, 04:09 PM
hey there another way to make sure your program stop if youre using windows is by putting the command
this will prevent it from closing till u press something;
I Speak in frequencies even dogs have trouble hearing