Solved

C++ question from a C# programmer

Posted on 2009-05-16
7
747 Views
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.

thanks
0
Comment
Question by:drewbuckley
  • 3
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
tculler earned 250 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,
Nate
0
 

Author Comment

by:drewbuckley
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 :)
0
 
LVL 3

Expert Comment

by:bandyt1712
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.

Andy
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:tculler
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,
Nate
0
 

Author Comment

by:drewbuckley
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.
0
 
LVL 9

Expert Comment

by:tculler
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

0
 

Author Comment

by:drewbuckley
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now