Can I simply change a file extension of .txt to say .cpp and be able to compile it? For C++

noob here, I have an IDE with all that stuff on another computer, but I need to submit an assignment by turning in the .cpp file on this computer and I have no IDE/c++ compiler.

I ask as I don't feel comfortable downloading software on someone else computer, so I just want to use notepad to create basic C++ code, then just change the extension to .cpp and upload it for a TA to grade.

Will this work, or do I need a compiler on this system?

Posted Oct 5, 2015, 1:45 AM UTC

07
gnomoretears•

Why do you need a compiler if you're just submitting the source code and not the compiled code?

The only time you'll need a compiler here is if you want to test and run the code before you turn in the source.

3
PyundaiOP•

okay, that makes sense... thanks! so a .cpp extension is just simply a .txt extension (for example) that's just named that way so the compiler recognizes it?

1
gnomoretears•

Pretty much yeah or rather a .cpp file is just a text file with a .cpp extension.

6
VermillionAzure•

All text files are not necessarily TXT, in fact, a file doesn't need a file extension; it's just standard convention.

Even so, source files for C++ either have CC or CPP extension.

3
POGtastic•

Sure, source files are just text files anyway.

The much more important thing to keep in mind is that you need to test your code before you send it in. The odds are extremely high that you've made typos, syntax errors, logic errors, and so on. Nothing will piss off the TA more than code that doesn't compile.

2
Heasummn•

Yeah, a .txt file is basically plain text. Your average programming language uses plain text as well, so yeah, you can just change the file extension.

I believe it is possible to make a compiler that will accept any kind of plain text file, but I haven't fiddled in compilers before.

1
HomemadeBananas•

Yes. You don't need to rename it. You can just use a cpp or cc extension when you first save it. but you should make sure it compiles. Find an online compiler if you can't install one.

1