1

I'm making a console application that shows the difference between continue and break when looping. I'm using c++ with visual studio 6.0. I added a new project and in NewProject.cpp I put this together:

// NewProject.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

void ContinueLoop(){

    for(int k = 1; k<5; k++){
        cout<<"This line shows once per loop cycle\n";
        continue;
        cout<<"Does this line show?\n";
    }

}

void BreakLoop(){

    for(int i = 1; i<5; i++){
        cout<<"This line shows once per loop cycle\n";
        break;
        cout<<"Does this line show?\n";
    }

}


int main(int argc, char* argv[])
{
    cout<<"This is the continue loop\n\n";
    ContinueLoop();
    cout<<"\nThis is the break loop\n\n";
    BreakLoop();

    return 0;
}

Now my question is: How do I move ContinueLoop and BreakLoop to a different cpp file that I can call up. I'm pretty new to c++ and the entire idea of having a cpp file and headerfile is new to me (learned a bit of coding in delphi 7 in highschool).

I've looked around, but I can't seem to find what I'm looking for on this site and most answers related are too specific to the situation or have confusing explanations. Give me the noob scrubbed down explanation of how to do this.

TheEvilMetal
  • 323
  • 2
  • 14
  • There are several questions (and answers) on Stackoverflow about this topic. In a nutshell: the program that compile every `.cpp` file is called a *compiler*, the program that put together compiled files and other libraries is the *linker*. `.h` files are nothing special, they are just useful to *share* the declarations of functions, classes, variables, etc. with multiple files. They are just **pasted** where you `#include` them. – Paolo M Nov 10 '15 at 07:38
  • I tried what that explanation gave, but I ended up getting the following error in methods.cpp: c:\new project\newproject\methods.cpp(27) : fatal error C1010: unexpected end of file while looking for precompiled header directive – TheEvilMetal Nov 10 '15 at 07:54
  • Found what I was missing. The new cpp file with the methods needed to include stdafx.h as well as my main cpp. – TheEvilMetal Nov 10 '15 at 11:59

0 Answers0