I’ve been studying a bunch C++ stuff and now I’m starting to hunker down a really work through this stuff. I’ve been basically going through Bruce Eckel’s, “Thinking in C++” line by line and I’ve gotten to the point where I’m getting ready to g++ with some of this source code examples. So far in the book he talks about the compiler but not exactly what to do. ( He doesn’t mention the ./a.out part at this point in book to generate output.)
Anyway maybe it’s further in the book…. But I found this quick wiki link on how to fire up some simple C++ program in Linux :http://gentoo-wiki.com/StartingCPP
Here goes:
jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ gedit JT_hello_world.cpp
jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ cat JT_hello_world.cpp
//JT’s Version of Hello World
#include <iostream>
int main ()
{
std::cout << “JT says Hello world in ANSI-C++ \n Yeah….. It works… \n”;
return 0;
}
jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ cat JT_hello_world.cpp
//JT’s Version of Hello World
#include <iostream>
int main ()
{
std::cout << “JT says Hello world in ANSI-C++ \n Yeah….. It works… \n”;
return 0;
}
jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ g++ JT_hello_world.cpp
jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ ./a.out
JT says Hello world in ANSI-C++
Yeah….. It works…
jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$
Alright… This is something celebrate in my Linux/C++/opencascade project. Actually having something working more or less on the first attempt….
For some reason, that just seems wrong…. so I’m going to intentional do something wrong to see what happens…..
basically the first gentoo example uses std::cout and in the prior to applying “using namespace std”. So… here goes:
jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ cat JT_hello_world.cpp
//JT’s Version of Hello World
#include <iostream>
int main ()
{
cout << “This should generate an error with the compiler because we don’t have ‘using namespace std’ in the program\n”;
return 0;
}
jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ g++ JT_hello_world.cpp
JT_hello_world.cpp: In function int main():
JT_hello_world.cpp:6: error: cout was not declared in this scope
jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$
Ok... Then... That's more like the stuff I've been used to seeing...... Alrightly..... Now lets put it all together and send the output to something other than a.out jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ gedit JT_hello_world.cpp jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ cat JT_hello_world.cpp //JT's Version of Hello World #include <iostream> using namespace std; int main () { cout << "Hello again world. I think we've got it and we're off to the next step...n"; return 0; } jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ g++ JT_hello_world.cpp -o i_got_it jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$ ./i_got_it Hello again world. I think we've got it and we're off to the next step... jonas@Ubuntu4:~/Documents/Thinking in CPP/Source/C02$
We'll actually first I need to bond with the family, try to sand some drywall and do a few other things first....