5

I'm currently a C.Sc student in India. We have lots of C++ to study but still is limited. Even if it goes the farthest, the toughest programs would be to make a library management system or a bank management system. The problem with the current syllabus is that it relies on the old C++ standards and we work on the old Turbo C++ compiler.

Sine I have a Windows 8 system, I can't make Turbo C++ to work seamlessly in my system. I would have to use DOSBox to emulate the executables. Moreover, I would like to switch to a newer compiler/IDE that's based on the latest C++ standards and fits for future education.

I tried Visual Studio and NetBeans and both are powerful and excellent. But I can't cope with these IDEs as I don't find ways to practice the silly codes I learn from school. We don't learn C++ to an extended level as I said before. The options in Visual Studio is to create a new project and I did that but it seems these 'Projects' are for app developers for developing programs based on C++. For a beginner like me, it's not helping.

I see a lot of people recommending Visual Studio Express for learning C++ but I can't seem to understand the working principles yet. Whenever I create multiple files in Visual Studio and debug them, all those files debug at once and I can't use main function for each and every C++ file as it reports an error.

I need to know how I can seamlessly create, edit and organize my C++ files in Visual Studio 2012. Or, if these are for app developers and enthusiasts, can you suggest me some other IDEs for practicing my codes without going into the complex parts?

sangeeth96
  • 1,202
  • 1
  • 11
  • 20
  • 1
    I don't know if I understand exactly what you are wanting. But even for simple C++ programs, the rule under VC++ is: _for each program you want a new project_, ie., for each `main()` function you write, you put it in a separate new project, under a separate new directory, etc... – Massa Jun 22 '13 at 14:49
  • As far as im aware you can only have one Main per project If you go on this link: http://thenewboston.org/list.php?cat=16 The tutorials will walk you through an IDE called CodeBlocks – Eduardo Jun 22 '13 at 14:53
  • 2
    I get the impression you are looking for a basic C++ application without a framework for app store or anything else. If this is the case then when you are creating a new Visual C++ project select Win32 and then Win32 Console Application. This will create a very simple project with a main(...) function. – John Sheridan Jun 22 '13 at 14:59
  • @Massa So, I need to create seperate projects for each and every single program I do in VS? We're not learning advanced C++ in our syllabus and as I said, the largest one we would practice would be to make a school management or bank management system using files. We code in a single file. So, for such simple coding, is VS necessary and are there any good alternatives to get the job done? I'm really into C++ but our syllabus is very limited. – sangeeth96 Jun 22 '13 at 15:04
  • yes, you have to create a project for each program. – Massa Jun 22 '13 at 15:06
  • @SangeethSudheer: If it's primarily for testing purposes, you might get some mileage out of making a console project with a single file and putting `#if 1 ... #endif` round the bit you're currently using and `#if 0 ... #endif` round previous small programs you've written. I have a project like this in which I try out answers to StackOverflow questions and it saves a lot of time. – Stuart Golodetz Jun 22 '13 at 15:06
  • @JohnSheridan Yes, exactly. But as Massa said, I need to create new project for every program I make right? That's the part I don't like. Is there anyway I can create and run .cpp files without making a Project? Although there's an option to create a new file instead of a project, it doesn't debug normally like it does when inside a project. – sangeeth96 Jun 22 '13 at 15:07
  • @clairharrison I'm thinking about that since VS feels like its for the serious programmers and devs. I love coding and I aspire to learn more but I'm still Level 2 or somwhere near Level 3 I guess. And I haven't started to develop serious stuff as my current knowledge is not enough. – sangeeth96 Jun 22 '13 at 15:20

4 Answers4

5

What I think you are trying to achieve is that you can have multiple small programs in a project. Now while visual studio doesn't allow this with these exact words it is possible to achieve this.

Using this setup:

Solution
    Project
    Project 
    etc.

This is done by going to: File -> new -> Project.. where you initially select the first project you want, for example: an empty project as this is probably what you are looking for. Now in the Solution Explorer you will see your project which allows you to add a new source file: "main.cpp" for example.

When you want to add another "main" you simply right click the solution and add a new project (which can be an empty project or any project).

Now when you want to run the other project you can simply rightclick the project file and select: "Set as startup project".


Possible project layout

Floris Velleman
  • 4,848
  • 4
  • 29
  • 46
  • 1
    Thanks for that Floris. Even if its still not the straight forward method I thought it would be, I guess this should do while using Visual Studio. And I guess I won't be having any more 'multiple main' problem if I make files in separate projects like this, right? – sangeeth96 Jun 22 '13 at 15:14
  • @SangeethSudheer You won't have that problem anymore ! – Floris Velleman Jun 22 '13 at 15:19
  • Yup. Tried it and its faster than creating new projects using File. Still, I don't think VS is suited for my current level studies. Can you suggest any other IDEs for beginners like me? – sangeeth96 Jun 22 '13 at 15:30
2

To have multiple self compilable single files in a project, you can exclude all other files except one which you want to compile.

Eg. Lets assume this hierarchy:


-Solution1
    -Project1
        -file1.c
        -file2.c

Now if one wants to compile only 'file2.c', thus excluding 'file1.c' from compilation, one can go properties of 'file1.c' and change 'Exclude from Build' field to 'Yes'.

sbhal
  • 145
  • 10
1

This guy does great videos, hh did a video on getting familiar with Visual Studio: http://thenewboston.org/watch.php?cat=39&number=3 The rest of the videos are for a different programming language but the IDE layout is all the same.

To start a new project: File -> Select C++ on the left hand side - > Console Application Give it a name and click ok. on the right hand side there will be the folder layout, right click src, add new file, select .cpp and give it a name.

This is your main

I hope this is what you mean and that video explains what you need to know!

Eduardo
  • 6,900
  • 17
  • 77
  • 121
  • Not exactly. In Turbo C++ (since I got accustomed with it), there's no need to create a project like in VS. You can create a new cpp file and save it wherever you like and run it whenever you want. In VS, I'm not finding an option like that. Since I'm a beginner and I'm still not developing any app or big programs, I need to know whether VS fits for my current level of studies. – sangeeth96 Jun 22 '13 at 15:18
  • I first learnt c++ on visual studio without any programming knowledge at all. Once you've set up your project then its just working with .cpp files from then on. Another option would be to use a website such as this: http://www.compileonline.com/compile_cpp_online.php Its an online c++ compiler. You only ever work with .cpp files and you can compile and run your program just by clicking the green arrow in the top left – Eduardo Jun 22 '13 at 15:29
  • @clariharrison, Understood. But you can't make two cpp files with `main` right? I first learnt to write a simple code for displaying 'Hello World!' and then later on to print Fibonacci series and stuff like that. If we were to do this again, we need to create separate projects for holding each cpp file right? Or is there a way to hold all of them in one single 'Project'? I assume not. – sangeeth96 Jun 22 '13 at 15:55
  • You can only have one main in a program, so only one in a project. You can have many cpp files in a project however providing only and exactly one of them has a `main`. So yes you would have to have two projects for those two programs. When you get further into c++ you will learn about functions that will allow you to call any "miniature program" so then you could have a hello world function and a Fibonacci function etc all within one project. – Eduardo Jun 22 '13 at 16:23
  • Thanks for that info. I already learned functions but never learned to link a cpp file with another. We just do everything in one. Thanks for the update. – sangeeth96 Jun 22 '13 at 17:48
0

This is my first answer, kindly bear with me. Improving the previous answer..

Eg. Lets assume this hierarchy:

-Solution1
    -Project1
        -file1.cpp
        -file2.cpp
        -file3.cpp
        -source.cpp

Create functions in file1.cpp or file2.cpp with whatever name you want instead of main function. Eg in file1.cpp

#include <>
int helloworld()
{
    //your code here
    return 0;
}

In file2.cpp

#include <>
int fibonacci()
{
    //code here
    return 0;
}

Now Write the Source function as:

#include <iostream>
//declare the functions defined in other cpp

int helloworld();
int fibonacci();

//Write the main function here and call the appropriate function from here

int main()
{
    int i;
    cin>>i;
    switch(i)
    {
         case 1: helloworld(); break;
         case 2: fibonacci();  break;
         // etc etc..
         default: break;
    }
    return 0;
}

Voila! It will be like turbo c++. This method has 1 drawback. All the cpps will get compiled. So, take a note of this. Good luck!