Errors in code with MinGW

Hello, I am trying to learn to use MinGW, as I am going through a set of tutorials. I have a piece of old code that I done from a book that works on visual studio, but when I try to run it with MinGW I am getting 2 errors that I do not understand, along with numerous warnings about null pointers, throughout the entirety of the code.

The errors I am getting are
1:3: error: expected unqualified-id before '/' token
1 |  ■/ *
| ^

Which is the very first line of the code, I understand it obviously has something to do with the comment and the / use, but I cannot understand why, especially since it works on visual studio.
The second error is,

cpp: 27:2: error: 'i' does not name a type
27 | }
| ^
This is the very last line of the code, the very last } to close off the code.

Does anyone know what could be causing these problems, and if so why these errors are showing here but they would not be in visual studio?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  /*
Write a C++ Program to Add Two Numbers. 

In this program, user is asked to enter two integers. Then, the sum of those two integers is stored in a variable and displayed on the screen.

*/

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

using namespace std;


int main()
{
	int num1, num2, total;

	cout << "Please enter a number for the first number" << endl;
	cin >> num1; 
	cout << "Please enter a number for the second number" << endl;
	cin >> num2;
	cout << "The total of these numbers is: " << num1 + num2 << endl;

	system("pause");

    return 0;
}

Well if your trying to compile with anything other than Visual Studio you you need to remove the stdafx.h header file.

I have tried taking out the stdafx.h, and still getting the same issue
Then perhaps you posted the wrong code. No where in the code you supplied is there a variable named 'i'.
I know, thats why I am so confused. I am 100% sure it is the correct code, as when it is giving warning with the null pointer, it shows some of the code for instance

1
2
3
4
5
6
7
8
9
AdditionOfTwoNumbers.cpp:18:1: warning: null character(s) ignored
   18 |    c o u t   < <   " P l e a s e   e n t e r   a   n u m b e r   f o r   t h e   f i r s t   n u m b e r "   < <   e n d l ;
      | ^
AdditionOfTwoNumbers.cpp:19:1: warning: null character(s) ignored
   19 |    c i n   > >   n u m 1 ;
      | ^
AdditionOfTwoNumbers.cpp:20:1: warning: null character(s) ignored
   20 |    c o u t   < <   " P l e a s e   e n t e r   a   n u m b e r   f o r   t h e   s e c o n d   n u m b e r "   < <   e n d l ;
It looks like you've managed to save a UCS-16 (wide character) file, rather than plain old ASCII.

mmm I just created a new visual studio project and then saved that, no idea how I could mess that up lol. But I will try with another solution I have, or try and create another project and see if it works this time.
Topic archived. No new replies allowed.