I'm using the g++ compiler and it can handle the basic stuff, but as soon as I try to use pointers it gives me errors. I 100% know the code is correct because I even pasted code from C++ Primer 5th Edition into it and it still isn't working. I did download a load of dev libraries when trying to install SFML so I'm thinking maybe that did it, but I don't know. I also don't have the slightest idea how to reverse it.
This is the code I pasted from C++ Primer 5th Edition, which apparently is the best book for learning. I've tried compiling it with g++ main.cpp -o main, and also with the -std=C++11 flag.
#include <iostream>
int main()
{
using namespace std;
int updates = 6;
// declare a variable
int * p_updates;
// declare pointer to an int
p_updates = &updates;
// assign address of int to pointer
// express values two ways
cout << “Values: updates = “ << updates;
cout << “, *p_updates = “ << *p_updates << endl;
// express address two ways
cout << “Addresses: &updates = “ << &updates;
cout << “, p_updates = “ << p_updates << endl;
// use pointer to change value
*p_updates = *p_updates + 1;
cout << “Now updates = “ << updates << endl;
return 0;
}
Why does this happen every time I try and learn anything new in C++?