# C++ or .Net programming?



## eddie5659 (Mar 19, 2001)

Hiya

I'm going to go back to programming, but the last compiler I used was Borland C++ version 3. I have version 6 in my shopping basket at Amazon, but was wondering if I should look at VB .Net.

The reason I'm curious, is that C++ doesn't seem to be mentioned anymore, and it may be a dying code. The version I can get for the same price is Visual Basic .NET Standard 2003 from Microsoft.

As they're retailed at ~£70, I don't want to get C++ and start learning again, and compiling a few programs, etc, to find out its no good. I know that .Net is for the web, whereas C++ is Windows based. But what are the other differences?

Look forward to any response, as I'd like to try and get out of my mundane job 

Regards

eddie


----------



## Andy Booth (Dec 26, 2004)

I always thought that .NET was just an extension of C++, so if you get C++.NET it wil do all the C++ stuff, with the added internet stuff, im probably wrong :S


----------



## Shadow2531 (Apr 30, 2001)

With .net, you can use regular c++.

In addition to creating regular programs, you can still create internet apps in good ol c++. It can be a lot easier to make them cross platform as they don't require the .net runtime environment. (there's mono for linux though).

I don't mess with VB or C# so I can't say much about them, but I think any of the visual studio programs are just a big pile of unnecessary bloat.

So for c++, I prefer gcc/mingw over MS compilers/IDEs. However, for some programs, only visual studio was considered when making the program and there could be more work needed to get certain programs to compile on other compilers.

With that said gcc 3.4.2 is probably the best free c++ compiler and you should probably use that first and then only buy something if it's necessary. (unless you go with vb or C#)

c++ is great (especially if you use the boost.org library). C++ is definitely not obsolete or even close.

Also, if you download the gcj package, you can compile java programs into standard executables that don't require a java runtime environment.

http://www.mingw.org/download.shtml
http://gnuwin32.sourceforge.net/packages.html

You basically setup a programming environment like linux. You can ./configure and everything. With mingw, you only setup what you want.

I've used visual studio and it's just a mess, but developing directx apps is a little easier. (You have to convert the dx libraries for use with mingw).

BTW, if you want to try an already setup version of Mingw 3.3.3, you can get it here http://www.nuwen.net/gcc.html

(look down the page for the "MinGW Distribution")

The guy's site, uses c++ to generate some of the content. He is also developing a forum created entirely in c++, which just shows you how cool c++ still is.


----------



## eddie5659 (Mar 19, 2001)

Thanks Shadow 

As I'm kinda used to the Borland compiler, I may just go for that, and continue to use C++. Once I get on top of that, I may then branch out to VB .Net

Those sites look very informative, so will bookmark them for future reference 

Many thanks for the explanation on what they both are, as I was a bit confused to say the least 

You mentioned the boost.org library. Can I use that with a different compiler, like Borland's?

eddie


----------



## Shadow2531 (Apr 30, 2001)

The boost library AFAIK works with any ISO C++ compiler, so if the compiler (and header files) are not too old, then all should be great.

If you want to download the boost library, goto http://sourceforge.net/project/showfiles.php?group_id=7586 , and downoad boost_1_32_0.exe.

Or pull the library off of cvs to get any new changes.

Anyway, boost_1_32_0.exe just contains the source files for the library. Many of the header files in the boost library don't require you to link to anything, but some do like regex. Don't be scared by all the files that are extracted. The "boost" folder contains all the headers. You should copy that folder to your compilers include folder.

But before you link to the libraries, you have to build them. You use a program called bjam (which is kind of like make). You can get bjam.exe from the link above too. You can build the whole library all at once, but I don't recommend that as that will just be a mess. Build only the libs you need. You shouldn't have to worry about any depencies when building boost (except for the python library in which you need python of course).

Here are directions on how to build it.
http://www.boost.org/more/getting_started.html#Build_Install

Since you are using borland, you would run bjam like this.

bjam "-sTOOLS=borland" stage

(some jamfiles are made to recognize the stage part, so you should leave that off if it throws an error).

For example, if you wanted to build the regex library, you would goto the *boost_1_32_0\libs\regex\build* directory and run the bjam command above.

The build script will then put the compiled libraries in *boost_1_32_0\bin*. It creates release and debug versions and dlls for each. For mingw at least, you'd be interested in the release libboost_regex.lib . You would change the extension from .lib to .a and place the file in the compilers lib directory and link to it like this.

g++ -Wall -Wextra file.cpp -o file -lboost_regex

I do not know how borland does it.

If you need more help setting it up just ask.

Now here's an example of what boost can do.

Say if you wanted to convert a string to int, you'd usually do it like this.


```
#include <iostream>
#include <sstream>

template<class T>
int to_int(const T& t) {
    std::stringstream ss;
    ss << t;
    int i;
    ss >> i;
    return i;
}

int main() {
    const int n = to_int("1234");
    std::cout << "\n" << n << std::endl;
}
```
but with boost, you could do it like this.


```
#include <iostream>
#include <boost/lexical_cast.hpp>

int main() {
    const int n = boost::lexical_cast<int>("1234");
    std::cout << "\n" << n << std::endl;
}
```
(boost/lexical_cast.hpp is one of the ones that doesn't require you to link to a library)

Boost has a whole bunch of functions/classes that compliment the stl. Boost is pretty essential.

List of boost libraries

If you want to replace every instance of something in a string and do it right, you'll want to use boost:regex_replace.


----------



## eddie5659 (Mar 19, 2001)

Thanks for this, i'm bookmarking this for when I get it and start working on it again. Not sure how advanced I'll get, but I will try my hardest 

Also, as I do online gaming, if I did download and install Python, would it conflict? I'm thinking it won't, as it needs to be running in the background, in the compiler.

I found this site as a basis to get me back into it:

http://www.cprogramming.com/tutorial.html

Its got a few popups, but apart from that it looks a good site. I'll be getting the main book with the compiler, but can you recommend any good books to help me move along?

Many Thanks once again

eddie


----------



## Shadow2531 (Apr 30, 2001)

Python should not mess with anything.

Some more links.

http://www.research.att.com/~bs/homepage.html
Specifically: http://www.research.att.com/~bs/bs_faq2.html
Book: http://www.research.att.com/~bs/books.html

http://www.cppreference.com/

If you setup python on winXP, I suggest you install python to c: so that python.exe is at c:\python\python.exe.

Then create c:\usr and then c:\usr\bin.
Then setup a hard link to python.exe in c:\usr\bin

*fsutil hardlink create c:\usr\bin\python.exe c:\python\python.exe*

If you install perl, do the same thing.

*fsutil hardlink create c:\usr\bin\perl.exe c:\perl\bin\perl.exe*

That's mostly for apache's sake so you can use *nix shebang lines properly. (you could just install to usr/bin , but most build scripts that need perl or python won't look there by default)

If using apache on windows, you'll want to add *ScriptInterpreterSource registry* to httpd.conf to help with paths for perl and python.

You can add perl and python to the PATH too.

(Win2K supports hardlinks, but I think you have to use a utility in a the toolkit on the win2k cd.)

Also, if you ask in the arsforum, you'll get good answers on programming.


----------



## eddie5659 (Mar 19, 2001)

Great, thanks. I'm using Windows 2000 now, so will look for the utility on my cd this weekend 

And thanks for the links, I'll look at them in more detail when I get my compiler. Buying it tonight.

I may be posting more on this subject, when I get to grips with it, but will also check out those forums 

Thanks once again, its appreciated

eddie


----------



## Shadow2531 (Apr 30, 2001)

I checked for you and I think win2K's version of fsutil is Linkd.exe and you get it when you install the windows 2000 resource kit that's on the Cd.

I think the usage is the same as fsutil, but not 100% sure and I'm not sure the Linkd can create hardlinks. It might only be able to create a junction point from one directory to another instead of file to file, but I'm sure you know how to use google to find out.

You have to be using ntfs though or you won't be able to do it anyway.


----------



## Shadow2531 (Apr 30, 2001)

Here's an unverified download for it.
Linkd.exe


----------



## eddie5659 (Mar 19, 2001)

Thanks


----------



## Nabeshin (Jan 9, 2005)

Some things in VS .net 2003 are pretty useful, but Visual Basic is not one of those. It is basically programming for people who do not know how to program. Usually these programs consist of a simple GUI and maybe a few variables.

C# is a very useful tool, and some have said it may replace C++. But, do to the way its set up, it will never be able to overthrow C++. But it is still a nice language to program in.

J# is another nive tool, but I haven't gotten into it (or java) at all.

Question, does anyone know where I can get some help with programming in C++ .net, because some of the stuff from older versions of C++ I cannot get working. I am currently learning C++ through a class at school that is suppose to be compiler independent, and work with any complier. But I cannot get the cout function to work inside of a C++ program, or any other basic program.


----------



## Shadow2531 (Apr 30, 2001)

For c++, both of these should work.


```
#include <iostream>

using namespace std;

int main() {
    cout << "\n" << "Hello World!" << endl;
}
```
or


```
#include <iostream>

int main() {
    std::cout << "\n" << "Hello World!" << std::endl;
}
```
I'm thinking those should compile under c++.net and I think you can even compile those under c# by including those c++ programs somehow.

Do those work for you?

Now, those are command line programs so you load them at the command line . Do not double-click on them to load them or they'll just pop up and disapear. (You can add cin.ignore() or system("pause") to the end of the program though so they don't disapear on you till you press enter.)


----------



## Shadow2531 (Apr 30, 2001)

Just to follow up on my mingw suggestion,

There's a release candidate of the mingw package that contains 3.4.2 versions of gcc.
http://prdownloads.sf.net/mingw/MinGW-3.2.0-rc-1.exe?download

Specifically these packages are installed.

gcc-ada-3.4.2.tar.gz
gcc-core-3.4.2.tar.gz
gcc-g++-3.4.2.tar.gz
gcc-g77-3.4.2.tar.gz
gcc-java-3.4.2.tar.gz
gcc-objc-3.4.2.tar.gz
binutils-2.15.91-20040904-1
mingw-runtime-3.6
w32api-3.2
gdb-5.2.1-1
mingw32-make-3.80.0-3
mingw-utils-0.3.tar.gz

That way, you don't have to download them separately and mess with everything.


----------



## Nabeshin (Jan 9, 2005)

What does

```
using namespace std;
```
 or

```
std::cout << "\n" << "Hello World!" << std::endl;
```
 do?

I have seen this in HelloWorld simple programs, but I have never seen it in my C++ programming class that I take.


----------



## Shadow2531 (Apr 30, 2001)

Standard Template Library functions and classes etc. are defined in the std namespace, which makes them members of the namespace "std".

When using things that are only defined in a namespace, you have to specify the namespace they are in.

You can do that globally or you can do it for each member.

For example, iostream is an STL header. It is needed for cout, cin, and endl etc and basic things.

So you can do "using namespace std;" and then use cout or you can omit the "using namespace std;" and use std::cout .

If you create your own header file, you'd do it for each member and not use the "using namespace" line.

In just a simple program, you can do it either way. Doing it for each member makes things less readable sometimes, but it allows you to differentiate 2 functions with the same name.

For example, say if you include some header that defines somefunction() that was defined in the namespace "bob" and you created your own function also named somefunction() that was not defined in any namespace, if you don't use "using namespace bob;", you can use both your function and the one in the bob namespace.

somefunction()
bob::somefunction()

For info on the different STL headers and std members
http://www.cppreference.com/

How does your teacher/professor do a hello world program?


----------



## Gazornenplat (Dec 30, 2004)

Nabeshin said:


> Some things in VS .net 2003 are pretty useful, but Visual Basic is not one of those. It is basically programming for people who do not know how to program. Usually these programs consist of a simple GUI and maybe a few variables.


Since all the .Net languages compile to IL, how can VB be less useful than C#?

Ian


----------



## Nabeshin (Jan 9, 2005)

Hey, thanks for the info Shadow2531!



> Since all the .Net languages compile to IL, how can VB be less useful than C#?


Don't know what "IL" is, but VB seems pointless to use if you know C++. It can make a nice GUI for a program, but if you involve any hard code (aka, simple stuff in C++), it is very difficult to use, or at least I have found it is.

With the correct training, you can program almost anything in VB, but anyone would recommend using C++ or another language for advance programs.

VB: Fun to build stuff with, but not for advance programmin'!


----------

