I’ve seen std::string used in a .c file. std is a c++ namespace and namespaces were introduced in c++. Why is that so? Shouldn’t it throw an error?
I’ve seen std::string used in a .c file. std is a c++ namespace and
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it will cause numerous compiler errors if it’s compiled as C code. If it’s being compiled as C++ instead, then it will compile fine. For example, GCC has the
-xoption to select the language to compile as, so you can compile a.cas C++ if you want with-x c++. Likewise, the Microsoft Visual C++ compiler has the options/Tcand/Tpto select a source language of C and C++ respectively.I suggest you fix your build system so that it doesn’t pass the
-x c++or/Tpflag to files not ending with typical C++ source file extensions (.cc,.cpp,.cxx,c++, and.C, though the last three are quite rare).