Recently, I figured out that Xcode could be used to write normal C++ programs.
My problem is with the following code :
#include <iostream>
#include <fstream>
using namespace std;
int main (int argc, char *argv[]) {
char operation='0';
int operand=0;
//open file for reading
ifstream ifile;
ifile.open (argv[1]);
if(!ifile.is_open()){
cout<<"Invalid file\n";
exit(1);
}
while(ifile.good())
{
ifile>>operation;
if(operation=='I') {
ifile>>operand;
cout<<"Inserting :"<<operand<<endl;
}
else
if(operation=='D') { cout<<"Deleting "<<endl;
}
}
return 0;
}
When the input is the following ,
I 4
I 8
I 10
I 9
*
When I compile and run in Xcode , I get the following
Loading program into debugger…
Program loaded.
run
[Switching to process 58116]
Inserting :0
Running…
Debugger stopped.
Program exited with status value:0.
I have set the filename as an argument in the project preferences.
However, in the Terminal , I get
Inserting :4
Inserting :8
Inserting :10
Inserting :9
Please help me understand why this happens.