c++ - Is there a way to compile and run a single .cpp file in a Visual Studio Express '12 project? -


i have started learning c++ , using microsoft visual studio express 2012. started project planning have .cpp files have run problem when try compile , run specific .cpp file doesn't work.

vs seems compile , run .cpp file main function in , makes .exe , runs it. since first .cpp file (that holds main()) simple hello world program getting 1 when try compile , run now.

i have .cpp file int age() function supposed ask users age , output it. it's simple , want run see in action can't figure out how compile particular .cpp file in project since seems want compile main .cpp file main() function.

how can compile specific .cpp in project?

all c++ programs start in main function. why don't try calling age() main?

of course, in order so, need main.cpp aware there function called age. header files come in.

in total, therefore need following:

main.cpp

#include "age.h"  int main() {     age();     return 0; } 

age.h

#ifndef age_h #define age_h  int age();  #endif 

age.cpp

#include "age.h"  int age() {     // age stuff.     return 42; } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -