C++ File Extensions: .cc, .cpp, .cxx, .h — What's the Difference and Which to Choose?
Hello everyone! I just started learning C++ and am writing simple programs in Visual Studio Code. I noticed that when I create a new file, I'm offered a bunch of extensions: .cpp, .cc, .cxx, and for headers — .h, .hpp, .hxx. I'm used to always using .cpp and .h because that's what was in the first tutorial. But recently I downloaded an open-source project on GitHub, and all the files there have the .cc extension. I tried renaming them to .cpp, but the compiler gave linker errors — it says it can't find some functions. I had to change them back.
Now I'm confused: are these extensions interchangeable or not? If yes, then why doesn't the .cc project work when I rename to .cpp? And if not, then which extension is considered 'correct' or 'standard'? Also another question: does the extension affect how the compiler processes the code? For example, can it confuse C and C++ files?
My example: I wrote a simple `Cat` class in a file `Cat.cc` and main in `main.cc`. Everything compiles with g++ main.cc Cat.cc -o app. But
No answers yet.
Log in to leave an answer
Blogs