Syntax error but not sure why

Hi,

I am currently on lecture 17 now. I am still confused about using the compiler to debug and get the message to write. I believe on a mac when I want to use the compiler to see if it will write the message I do the following: Type: ./TripleX.cpp and then hit enter to see if it will print the message for the game. Is that correct?

When I do this I get this message but not sure why?

./TripleX.cpp: line 3: syntax error near unexpected token `(’

./TripleX.cpp: line 3: `int main() ’

This is what my code looks like below currently. Added spaces between iostream to make sure it shows up in the post.

#include < iostream >

int main()
{
std::cout << “You are a secret agent breaking into a secure server room”;
std::cout << std::endl;
std::cout << “You need to enter the correct codes to continue…”;
return 0;
}

I have looked through google posts to see if I can figure out how to solve this matter but I cannot figure out what to do. Any help would be much appreciated!

Thanks,
Todd

Hi Nina,

I am not quite sure if you edited something on my original question/post? Is there a way to see what you changed because I looked line by line but couldn’t see any differences. Please let me know how I am supposed to read the side by sides. (It seems like a side by side edit?) I would love to understand why I am getting this syntax error so I can go forward with the course!

Thanks,
Todd

That is not correct. g++ is the compiler and you provide it files you want to compile. -o is to be able to name the executable that is output. If you don’t then by default it will be called “a.out”

g++ TripleX.cpp -o TripleX

This will create the executable file called “TripleX” (note the lack of .cpp) if you give it a different name after -o it’ll be called that instead e.g.

g++ TripleX.cpp -o Bananas

Would create an executable file called “Bananas”.

To then run the program you need to type the name of it as well as the path to it. That’s what . is for, it means the current directory.

./TripleX # or Bananas if you opted to call it that..

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms