Error: main.cpp: warning: using directive refers to implicitly-defined namespace ‘std’
If you see the following error when trying to compile a C++ application:
main.cpp: : : warning: using directive refers to implicitly-defined namespace 'std' |
then that means you do not have any header file inclusion that uses std namespace.
You can fix this warning by including a C++ header file that uses a std namespace otherwise the compile will not know about std namespace.
Example: Implement a Stack of Strings in C++
Next example show how to implement a class of strings in C++. We will first read a text from a file and we will store it into a C++ string. Then we will split the string into words (by spaces) and we will store the words in a vector of strings.
Then we will iterate through that vector of strings and we will add elements our stack only if element not equal with “-“. If element is equal with “-” character then we will pop element from top of stack. We will display elements that we remove (using pop()) from our stack.
Class ReadFromFile
Class ReadFromFile header file (ReadFromFile.h):
#include <iostream> #include <fstream> using namespace std; class ReadFromFile { private: string fileName; long long buffLength; string buff; public: ReadFromFile(string file); ~ReadFromFile(); string displayBuffer(); long long getFileLength(); }; </fstream></iostream> |
no matching function for call to ‘glutinit’
If you get this error in Xcode:
no matching function for call to ‘glutinit’
when you are trying to write a simple program with Glut a quick fix is to remove “const” from:
int main(int argc, const char * argv[])
C Plus Plus Error: undefined reference to `std::basic_string, std::allocator >::basic_string()’
Score.cc:(.text+0x11): undefined reference to `std::basic_string
Score.cc:(.text+0x2a): undefined reference to `std::string::operator=(char const*)’
Score.cc:(.text+0x5d): undefined reference to `std::basic_string
Score.cc:(.text+0x82): undefined reference to `std::terminate()’
/tmp/Score-AOj1oH.o: In function `Score::~Score()':
Score.cc:(.text+0xb1): undefined reference to `std::basic_string
/tmp/Score-AOj1oH.o: In function `Score::GetPlayerName()':
Score.cc:(.text+0xe8): undefined reference to `std::basic_string
/tmp/Score-AOj1oH.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0′
clang: error: linker command failed with exit code 1 (use -v to see invocation)
To solve this error compile using -lstdc++ option (which links to stdc++ library):
clang -lstdc++ Score.cc main.cc
or:
g++ -lstdc++ Score.cc main.cc