problems with ./a.exe

I've just started learning c++ and I am currently watching a youtube series on how to progress, I am having problems with g++ filename.cpp and ./a.exe when I use g++ it should save my newest line of code that I have inputted if I am correct, but when I go to test the code using ./a.exe I get the same line of code that has no changes at all. I will leave my code down below.


The response when I type ./a.exe is " You Have 10 slices of pizza.
10."

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

using std::cout;
using std::cin;

int main()
{
	int slices;
	cin >> slices; 
	cout << " You Have " << slices << " slices of pizza." << std::endl;

}
Last edited on
When you type "g++ filename.cpp", do any errors get spit out?

Btw, if you want an actual name for the exe, you could do something like
g++ filename.cpp -o filename

Also, turning on warnings (at least -Wall) can help find bugs before they happen.
g++ -Wall filename.cpp -o filename

Your current code does not compile,
 In function 'int main()':
8:2: error: 'cin' was not declared in this scope
8:2: note: suggested alternative:
In file included from 1:0:
/usr/include/c++/4.9/iostream:60:18: note:   'std::cin'
   extern istream cin;  /// Linked to standard input
                  ^


Use std::cin or add using std::cin;

When in doubt, delete the old executable and re-do the steps you're following.
Last edited on
when I do "g++ filename.cpp" I get no errors. I have added using std::cin;
Last edited on
I have also deleted the old executable and ran g++ filename.cpp and it creates a new executable but it still runs the old code for some reason. What I was told in the video it shouldn't run anything and it should be blank in the console when I do ./a.exe
Last edited on
Don't forget to press 'Save' in your editor as well.

Forgetting to save means recompiling the old program, and still getting the old results.
Topic archived. No new replies allowed.