Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-21-2003, 08:57 AM
|
#1
|
Member
Registered: Feb 2003
Location: 127.0.0.1
Distribution: Latest Ubuntu
Posts: 161
Rep:
|
Is not all C++ written equal?
I want to make the transition from programming in Microsoft Visual to programming in KDevelop. I thought it would be pretty straitforward, C++ is C++ after all. I did learn the "Using namespace std" thing, but I still cant compile any of my programs that worked fine in MSVisual, after adding "using namespace std"
Is it just the compiler or for some reason is the code different in Linux? If its the latter, I need to find a documentation on programming for linux. Preferably one for complete beginners, starting of with "hello world" Either that or im just going to go back to MSVisual. Any help would be appreciated, maybe someone has gone through the same thing?
Last edited by Fingel; 02-21-2003 at 07:55 PM.
|
|
|
02-21-2003, 09:04 AM
|
#2
|
Member
Registered: Feb 2003
Location: Brasil
Distribution: Debian Etch
Posts: 147
Rep:
|
What errors do you get when compiling?
Searching google/linux for info on that. You will surely find someone who had the same problem and will show you what are the diferences.
|
|
|
02-21-2003, 09:10 AM
|
#3
|
LQ Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018
Rep:
|
If you're used to programming in Visual C++, you're probably used to some of the Windows API (the functions used for creating windows, dialog boxes, drawing stuff on the screen, etc.), which is not going to work in Linux. Yes, C++ is C++, but keep in mind that C++ is simply a language. Function names are like words, and Linux has a different vocabulary than Windows.
There are lots of programming resources online. Google will give you tons. Also, you can get the source code for just about anything in Linux, meaning you can always study that and learn from it!
|
|
|
02-21-2003, 09:58 AM
|
#4
|
Member
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637
Rep:
|
g++ supports the Standard C++ STL while MSVC++6 has scant support of the STL and uses it's own classes for example it uses some class called Cstring instead of the STL string class. Microsoft fixed that in VC++7, but it is not reflected in MFC unfortunately, yet not even Linux widget sets support Standard C++. So the GUI libraries are just totally different on both platforms (since there is no standard support on either!).
If you wanted a cross platform solution, than you would have to use Java < http://members.shaw.ca/trollking/ >.
Although I admit, that I don't know what the newest QT versions are like, nor the newest GTK+. Maybe they are more ANSI compiant.
Last edited by GtkUser; 02-21-2003 at 10:04 AM.
|
|
|
02-21-2003, 11:34 AM
|
#5
|
Member
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647
Rep:
|
C++ is C++ but dfferent platforms added their own libraries to add the functionalities. The core language and standard libraries are more or less the same, and you shoud be able to compile the programs using only the standard libraries with no or little changes. But each platform adds their own libraries. You might want to search "Linux C++ programming" in the google and you will get tons of tutorials.
Last edited by moeminhtun; 02-21-2003 at 11:39 AM.
|
|
|
02-21-2003, 12:17 PM
|
#6
|
Member
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637
Rep:
|
Not really unfortunately. For example Microsoft VC++6 does not support the STL very well at all. So I'd have to totally 100% disagree that MSVC++ is Standard C++, or that toolkits like QT or MFC conform to ANSI.
The only fortunate thing is that g++ and the new MSVC++7 are ANSI compliant, however their toolkits and API's are not ANSI compliant, and that is not good.
If you don't believe me than try titles from the Bjarne Stroustrup series (the creator of C++) or a book like C++ Primer 3rd edition on MSVC++6. Than you'll know what a piece of junk MSVC++6 is! Than read about the Linux toolkits that state they are not compliant with Standard C++, they have a ways to go. The fact is that Standard C++ is the most sophisticated langauge around, and I'd like to use it with a widget set on Linux, but that isn't possible yet, or at least not without creating your own Widget set from Xlib.
Last edited by GtkUser; 02-21-2003 at 12:35 PM.
|
|
|
02-21-2003, 07:51 PM
|
#7
|
Member
Registered: Feb 2003
Location: 127.0.0.1
Distribution: Latest Ubuntu
Posts: 161
Original Poster
Rep:
|
Ouch. I've been programming in MSVisual C++ 6, looks pretty bad. But I get syntax errors on the simplest programs. For example:
#include <iostream>
int main ()
using namespcae std;
{
long games, computer, total;
do {
cout << "how many times do you play video games a week?: ";
cin >> games;
cout << "how many times do you use the computer a week?: ";
cin >> computer;
total = games + computer;
cout << total;
cout << "If you want to go again, type 1 for yes and 0 for no.";
} while (again !=0 );
return 0;
this little one produves errors like games and computers are undeclared, and that there are syntax errors before >> and <<<
This worked toatally fine in MSVisuall C++, but I gues it just sucks.
Last edited by Fingel; 02-21-2003 at 07:53 PM.
|
|
|
02-21-2003, 10:10 PM
|
#8
|
LQ Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018
Rep:
|
I have heard several reports that Visual C++ is not an ANSI compliant compiler, which means it will probably accept syntax that is really not valid. Instead of just saying "long" try "long int" or "long unsigned int", etc.
Another thing I have been told about one of Visual C++'s quirks, is in the following situation:
for ( int i = 0; i < 10; i++ )
... some stuff
for ( int i = 0; i < 10; i++ )
.. some other stuff
This is legitimate, ANSI-compilant C++. The variable i should be in scope only for the duration of the for loop, which saves the hassle of declaring it outside the for loop. But Visual C++ keeps it in scope, so the second for loop causes errors about multiple declaration. Fun, eh? Guess the MS guys didn't work too hard on compliance.
|
|
|
02-21-2003, 10:27 PM
|
#9
|
Member
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647
Rep:
|
I made a little bit changes to your program.
The problem is you miss placed the "using namespace std".
Try to copy and compile the following program.
It's working fine.
#include <iostream>
int main ()
{
using namespace std;
long games, computer, total;
int again;
do {
cout << "how many times do you play video games a week?: ";
cin >> games;
cout << "how many times do you use the computer a week?: ";
cin >> computer;
total = games + computer;
cout << total;
cout << "If you want to go again, type 1 for yes and 0 for no."; cin >> again;
} while (again !=0 );
return 0;
}
Last edited by moeminhtun; 02-22-2003 at 02:43 AM.
|
|
|
02-22-2003, 04:10 PM
|
#10
|
LQ Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018
Rep:
|
Quote:
Originally posted by moeminhtun
I made a little bit changes to your program.
The problem is you miss placed the "using namespace std".
Try to copy and compile the following program.
It's working fine.
|
I've always seen the 'using namespace std' outside of any function definitions. I don't think it belongs inside of main, since it's really a compiler directive, rather than part of the main function.
Though, I just noticed that Fingel has 'namespace' misspelled. Fingel, if you copy-pasted this program, you might want to see if correcting the spelling helps 
|
|
|
02-23-2003, 12:21 PM
|
#11
|
Member
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647
Rep:
|
Yeah! actually should be outside of the function definitions, like,
#include <iostream>
using namespace std;
But If you put it inside the main function, it still works. I just followed his flow of the program.
|
|
|
02-23-2003, 12:26 PM
|
#12
|
Member
Registered: Feb 2003
Location: 127.0.0.1
Distribution: Latest Ubuntu
Posts: 161
Original Poster
Rep:
|
heh, dont worry I didnt cut and paste that. I just typed it real fast. Ive been told to put "using namespace std" right after the include statement, i'll try it the other way.
|
|
|
02-23-2003, 12:40 PM
|
#13
|
Member
Registered: Feb 2003
Location: 127.0.0.1
Distribution: Latest Ubuntu
Posts: 161
Original Poster
Rep:
|
hey! I put "using namespace std:" inside of the main function and it compiled perfectly! Luckily I havent been using a tutorial for MSVisual C++ 6, just C++ general, so I shouldent run into any miscompatibilities, should I? The tutorial id written for Windows users and recommends Borland. I hope Borland isnt as bad as Visual. 
|
|
|
All times are GMT -5. The time now is 07:44 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|