0

My .exe file won't run if the file I compiled is .h type.

This is the C++ code I put:

#include <iostream>
using namespace std;

int main(){
    int var = 0, sum = 0;
    while (std::cin >> var){
        sum += var;
    }
    std::cout << "sum " << sum << std::endl;
    return 0;
}

I use MinGW for compiling, and I named the file CTesting.h and compiled it and I get the following error running the exe:

The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether your need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.

I do not get this error when I rename the source fill to a .cpp type. It is my understanding that C++ used .h and .cpp files, is that incorrect? or am I doing something wrong/forgetting something?

Cœur
  • 37,241
  • 25
  • 195
  • 267
aaroniey
  • 15
  • 5

1 Answers1

0

You can't use .h extension here! MinGW will recognise CTesting.h as a header file. You have to use a source file extension (eg. .cpp for C++ or .c for C), so GCC can determine it correctly.

Please see here for a list of all file extensions and here for GCC manual about header files.

Cœur
  • 37,241
  • 25
  • 195
  • 267
ollo
  • 24,797
  • 14
  • 106
  • 155