-
New to C++
Hello to all,
I am a newbie to C++ and trying to get started with a tutorial book. My first hiccup is with my first program. I can't get it to compile. Heres the code:
Code:
#include <stdafx.h>
#include <iostream>
using namespace std ;
int main()
{
cout << "Never fear, C++ is here!" ;
return 0 ;
}
The error I receive is that the file "stdafx.h" cannot be found. I am working on a Mac OSX and have had no problems programming in C. Any suggestions would be great.
-
Remove the #include <stdafx.h> line.
It's for when compiling with precompiled headers with Visual Studio, but you aren't using VS.
-
I have taken out that particular header file but have received other errors.
when i compile with the command:
gcc file.cpp -o file
I get the following error:
ld: can't open output file for writing: print1
collect2: ld returned 1 exit status
I tried compiling with a different output name but received a lot of other errors:
Undefined symbols:
"___gxx_personality_v0", referenced from:
___gxx_personality_v0$non_lazy_ptr in ccTcu6UL.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccTcu6UL.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccTcu6UL.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccTcu6UL.o
"std::cout", referenced from:
__ZSt4cout$non_lazy_ptr in ccTcu6UL.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
any suggestions???
-
-
Yes: you have to use g++. gcc is for compiling C programs. g++ is for C++.
[edit] That would be the cause of the second error. For the first error, perhaps you already have a program called "file" that you don't have write permission to, or something like that. [/edit]
Note: you can use [noparse][/noparse] tags to disable the board's parsing of smileys if you want to, thus avoiding the above.
-
Thank you for the help. I did not know that the terminal command would be:
c++ file.cpp -o file
I appreciate the help.