Starting a new project

Mar 22, 2010 at 7:21pm
Win32 > Console Application > (Empty)
What do I do to start writing code?
Mar 22, 2010 at 7:24pm
what IDE are you using?
Mar 22, 2010 at 7:54pm
Win32 > Console Application > (Empty)


That sounds a bit like Visual Studio, right? Once you create a project you should be able to right-click on the 'Header Files' and 'Source Files' folders in the solution explorer and add header/source files respectively. Is that what you mean?
Mar 23, 2010 at 7:33am
Yes, I am using Visual C++. I am only 13 but I want to learn the basics of C++.

What is the difference between header and source files?
Mar 23, 2010 at 7:38am
You are meant to write code in the source files and write prototypes in the header. Here is an example:

headerfile.h:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <cstdio>

void SomeFunction(void);

struct someStruct
{
int a;
int b;
someStruct();
~someStruct();
};


Some .cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "headerfile.h"
void SomeFunction(void)
{
//code
}

someStruct::someStruct()
{
//code
}

someStruct::~someStruct()
{
//code
}
Mar 23, 2010 at 7:57am
What about the thing it teaches in the first section of 'Documentation'.... the 'Structure of a Program', that doesn''t exactly look like 'My first program'
Mar 23, 2010 at 8:02am
The first program you do will probably be in one file, meaning you won't need header files. Just a main. Are you familiar with writing other functions aside from main?
Mar 23, 2010 at 8:08am
To be honest if you are following the tutorial, you don't want to worry about header files for a little bit. Just work with the one source file. The header files are useful when you have multiple source files that call functions written in a different file. (It might seem a little confusing, but let me clarify)

You write some code that uses a function called SomeFunction. You write it in a file called SomeFunction.cpp, but you can't access it from another file that is written later, as that file does not know about the function. Putting a prototype in the header file means you can call the function in another file as long as you include the header file.

An easy example of this is when you use functions in iostream or stdio. Those functions are written in some other file, but the header contains prototypes so the compiler knows what the function takes and returns.
Mar 23, 2010 at 4:45pm
Visual C++ > Win32 > Console Application > Empty > Inserted .cpp in Source Files > Copied code from 'My First Program' > clicked DEBUG > START DEBUGGING > Error Message: "There were build errors"
Mar 23, 2010 at 6:25pm
I started a new, Empty, Win32 Console application. I inserted a C++ file (.cpp) into 'Source Files' and put the code from the documentation 'Structure of a Program' in it. When I click 'run' it says there were 'Build errors' and doesn't load.
Mar 24, 2010 at 6:13pm
Can you post the code, and also the build errors you are getting?
Mar 24, 2010 at 9:38pm
Headers contain data for use by other programs. Headers are (with some rare exceptions) NOT compiled. They serve as packages to store classes and functions for use by the general programmer. Headers should not contain the implementation of any function, excepting templates. There's an article around here on specifics. To draw on the majority of standard C++ libraries (all of them afaik) you need to include them by #including the header files. Headers are, essentially, designed to make clear a continuous and standardized declaration of stuff you intend on using, so you don't mess that stuff up between files.
Source files contain the actual code you will be executing. Source also contains the implementation of functions and they will also contain your main().
And if you use void main() you can't even call yourself a programmer. It's int main or nothing.
Check the tutorial on this site for the essentials; there's tons on this place.
Mar 25, 2010 at 11:11am
I don't know the build errors it just says "There were build errors". I used the exact same code from the documentation "Structure of a program". The code is in a .cpp file in the 'Source Files' .
Mar 25, 2010 at 4:57pm
You should build your project separately (i.e. don't try to run it). Right-click on the project node in the 'Solution Explorer' tab (click 'View->Solution Explorer' if you can't see it), and then select 'Build'. You should then be able to tell us the errors that appear in the 'Error List' (click 'View->Other Windows->Error List' if you can't see it).
Topic archived. No new replies allowed.