LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 02-21-2003, 08:57 AM   #1
Fingel
Member
 
Registered: Feb 2003
Location: 127.0.0.1
Distribution: Latest Ubuntu
Posts: 161

Rep: Reputation: 30
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.
 
Old 02-21-2003, 09:04 AM   #2
loke137
Member
 
Registered: Feb 2003
Location: Brasil
Distribution: Debian Etch
Posts: 147

Rep: Reputation: 15
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.
 
Old 02-21-2003, 09:10 AM   #3
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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!
 
Old 02-21-2003, 09:58 AM   #4
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
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.
 
Old 02-21-2003, 11:34 AM   #5
moeminhtun
Member
 
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
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.
 
Old 02-21-2003, 12:17 PM   #6
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
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.
 
Old 02-21-2003, 07:51 PM   #7
Fingel
Member
 
Registered: Feb 2003
Location: 127.0.0.1
Distribution: Latest Ubuntu
Posts: 161

Original Poster
Rep: Reputation: 30
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.
 
Old 02-21-2003, 10:10 PM   #8
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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.
 
Old 02-21-2003, 10:27 PM   #9
moeminhtun
Member
 
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
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.
 
Old 02-22-2003, 04:10 PM   #10
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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
 
Old 02-23-2003, 12:21 PM   #11
moeminhtun
Member
 
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
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.
 
Old 02-23-2003, 12:26 PM   #12
Fingel
Member
 
Registered: Feb 2003
Location: 127.0.0.1
Distribution: Latest Ubuntu
Posts: 161

Original Poster
Rep: Reputation: 30
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.
 
Old 02-23-2003, 12:40 PM   #13
Fingel
Member
 
Registered: Feb 2003
Location: 127.0.0.1
Distribution: Latest Ubuntu
Posts: 161

Original Poster
Rep: Reputation: 30
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why LInux is Written in C and in C++? Jatinm Programming 15 01-30-2005 10:03 PM
have you ever written a program for linux? today53 General 33 12-05-2003 06:54 PM
PGP written by me in java, but I need help a little Laptop2250 Programming 9 11-23-2003 03:21 PM
how to are logs written to? robadawb Linux - Newbie 1 11-11-2003 03:56 AM
Is fluxbox written in C or C++?? purpleburple Linux - Software 1 11-18-2002 05:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration