C++ question from a C# programmer

Posted on 2009-05-16
Medium Priority
Last Modified: 2013-11-25
Shoule be an easy question for you c++ people.

I've downloaded and want to work with the JRTPLib which is in C++ and has some examples. These are the .cpp files.
i have VS2008 and i'm not sure how to create a project so that i can test these examples.

i would also like to use these as a starting point for myself to learn C++. You may say that if i cant do this maybe i need to learn C++ from the beginning, well, good point but i haven't the time. Once i can get a project of these .cpp files, i'm confident to learn as i go.

Question by:drewbuckley
  • 3
  • 3

Accepted Solution

tculler earned 750 total points
ID: 24407917
Well, I'm a C# programmer as well, but I know a thing or two about C++ ;). However, I am using VS 2005, so I hope things won't be too different.

Despite the similar names, C++ and C# are totally night and day; VERY little is the same. The syntax is fairly similar in the structuring aspects (for loops, while loops, if statements, etc), but the way C++ creates classes and such is much more complex (in a beneficial way, though).

I'll get you off to a very rough start though; you'll find that many changes will need to be made from here. When you start up VS, hit New Project... like you usually would for a new C# project. Instead, look for the C++ tab in the tree view there for the language selection. C++ may be one of the nodes, or it may be nested in another node called "Other Languages", or something similar. Select a "C++", "Visual C++", or similar node. If you're using "Managed" C++ (basically just C#, but with C++ syntax, lol), select a CLR Project (you can create a CLR Windows Application, CLR Console Application, or, my favorite, a CLR Empty Project). If you're using MFC, choose MFC; if you're donig a library, choose Class Library, and so on, so on. You're probaboly doing Native, so I would just start with an Empty Project for now.

When you're project is created, right click on the "Code Files" Filter (the icon looks like a folder, but it's really not; it's called a Filter). Click Add New Item, or something similar to that; from the templates, search for Code File (.cpp), name it, and hit ok. In your program, unlike C#, you don't need your main method nested within a class (in fact, I don't believe it can be!). Just have it floating in your code file; either int main() or void main(), etc.

EVERYTHING is sequential in C++, so you're header references and such MUST go before the first time you use them. Most everything in the standard C++ libraries reside in the namespace called "std" (yikes, poor name choice, eh? lol). Instead of "using NamespaceName;" in C#, you use "using namespace NamespaceName;". Before you can do this, however, you must "import" (or "include") some files to utilize. Get the full path to your files (the cpp files you mentioned that you want to include), and put

#using "PathToFile.cpp"

Notice the lack of the semi-colon. Anything prefixed with the # operator specifies a Pre-Processor directive.

Anyways, repeat that process shown directly above for all of your files, and you should be good to go. Sorry this explanation is so long--sadly, there is MUCH more you need to know. However, you said you're in for a learning experience, and this'll get you started :)

Good luck!

Hope I helped,

Author Comment

ID: 24408766
Thanks for your time Nate.

I'm sure it's me but this is what i did.
started new project normal empty project and also tried your one, clr empty.
i added a .cpp file and named it "main" and inserted #using "the path to the example cpp file". on compiling i get "C1113 using failed on -----------" if i import the example.cpp into the source folder i then get around 100 errors of ; missing before and such. these errors are coming from the headers of the library that the example is from. i have pointed to this in c++ directories include files.

i think c++ doesn't like me :)

Expert Comment

ID: 24418639
I think you can use the wizard to let VS 2008 build the solution file from the directory containing the source code.(File->New->Project From Existing Code)  May be you have to tweak some project properties like /clr a.s.o

C++ compiler always spit a lott of error messages even on one single error.
Please post the first dozen lines of the error log when you run into trouble.

Hope that helps.

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Expert Comment

ID: 24424548
Whoops, that was my bad. I meant #include, heh. So it'll be

#include "PathToFile.cpp"

The "Pre-Processor" basically searches for this file, and inserts it directly into your file. To indicate header files int he standard library, you use angle brackets (< >) instead of quotes. For example,

#include <iostream>

Includes the standard header file iostream. However, since your files are not in the standard library, you give the path in quotes.

Sorry about that heh,

Author Comment

ID: 24426826
Thank you for your help.
I've tried both ways and am getting over 40 errors which is way too many to go through here.

One thing though. I've noticed that there is a Makefile.in and believe that this can make the Projectect but i can't seem to make it happen,

Google has told me to use NMake.exe i have tried c:\NMAKE /f "Makefile.in" amonst other things with no success.

is this right? is there another way?

Once again sorry for my noob questions and i appreciate your help and patience.

Expert Comment

ID: 24428310
Alright, do me a favor; we'll see if this works. Follow these steps:

- Start up VS, and go to the Visual C++ templates section. Create a new Empty Project. There should be nothing in any of your filters.
- Right click on your "Source Files" filter, and click "Add...", "New Item".
- On the left hand side, select the "Code" node from the small tree view.
- Select "C++ File (.cpp)" from the choices. Name it however you feel appropriate. A blank page should show up.
- Type the lame code in the following code snippet.
- Run the solution; a console window should come up and display the String shown below (to the right of the "<<", which is called the Insertion operator in this context. It's not shifting bits.)
#include <iostream>
using namespace std;
void main()
     int test = 0;
     cout << "If this doesn't work, drewbuckley's VS is friggin screwy. Enter a number, we'll keep going, lol *gotta love console apps!*:" << endl;
     cin >> test;
     test *= 2;
     cout << "kk here's your number doubled: " << test;

Open in new window


Author Comment

ID: 24428355
That works and was pretty funny:)
also funny how a C# guy helps another C# guy in C++ ;)

seriously though thanks and what now? i appreciate your time.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question