Reputation: 33
Note: I do have xcode installed as well as its command line tools.
gcd.cpp:6:20: fatal error:
iostream
: No such file or directory
Is the error I get in terminal when running:
g++ gcd.cpp -o gcd -g -Wall -Werror -pedantic-errors -fmessage-length=0
I have no idea how to fix this issue. Any one know how to fix it?
#include <stdio.h>
#include <iostream>
#include <sstream>
using namespace std;
int gcdRecur(int a, int b) {
if(b == 0)
return a;
else
return gcdRecur(b, a % b);
}
int gcdIter(int a, int b) {
int z;
while(b != 0) {
z = b;
b = a%b;
a = z;
}
return a;
}
int main(int argc, char *argv[]) {
if(argc != 3){
printf("Usage: %s <integer m> <integer n>", argv[0]);
return -1;
}
string m_str = (string) argv[1];
string n_str = (string) argv[2];
istringstream iss;
int m = 0, n = 0;
iss.str(m_str);
// Check if the first argument is an integer
// by giving the istringstream 0
if(!(iss >> m)){
cerr << "Error: The first argument is not a valid integer." << endl;
return -1;
}
iss.clear();
iss.str(n_str);
if(!(iss >> n)){
cerr << "Error: The second argument is not a valid integer." << endl;
return -1;
}
int iter = gcdIter(m, n);
int recur = gcdRecur(m, n);
printf("Iterative: gcd(%d, %d) = %d\nRecursive: gcd(%d, %d) = %d\n", m, n, iter, m, n, recur);
fflush(stdout);
}
UPDATE
Running the command:
g++ -H gcd.cpp -o gcd -g -Wall -Werror -pedantic-errors -fmessage-length=0
I now get this output(it will do the same error for sstream if I switch the order of it and iostream):
. /usr/include/stdio.h
.. /usr/include/sys/cdefs.h
... /usr/include/sys/_symbol_aliasing.h
... /usr/include/sys/_posix_availability.h
.. /usr/include/Availability.h
... /usr/include/AvailabilityInternal.h
.. /usr/include/_types.h
... /usr/include/sys/_types.h
.... /usr/include/machine/_types.h
..... /usr/include/i386/_types.h
.... /usr/include/sys/_pthread/_pthread_types.h
.. /usr/include/sys/_types/_va_list.h
.. /usr/include/sys/_types/_size_t.h
.. /usr/include/sys/_types/_null.h
.. /usr/include/sys/stdio.h
.. /usr/include/sys/_types/_off_t.h
.. /usr/include/sys/_types/_ssize_t.h
Upvotes: 0
Views: 1126
Reputation: 83
You'll want to make sure that you have the Xcode command line tools installed. From the terminal run:
xcode-select --install
Whenever I get stuck trying to figure out what the compiler did in Xcode, I always go to see what the command Xcode used was. In your project go to the Report navigator (should be on the left hand side, far right tab):
Then find the line for the file that you are interested in seeing further:
Click on the little stack of pancakes on the far right to expand:
Upvotes: 1