| | |
string in namespace std does not name a type
![]() |
•
•
Join Date: Mar 2008
Posts: 27
Reputation:
Solved Threads: 0
Hi guys. I'm aware of the requirement to specify std:: as the namespace for string in some way ( whether it be using namespace std etc) - but the following error has stumped me as to its cause.
This is the only error - and here is a (truncated) Conf.cpp.
Line 33 as shown in the code sample is the definition of the function returning a string.
I've tried combinations of using std::string, but each time it states something similar "string does not name a type", "std::string has not been declared" etc..
Any suggestions would be most helpful.
Thanks,
PC_Nerd
C++ Syntax (Toggle Plain Text)
$ g++ Conf.cpp Conf.cpp:33: error: ‘string’ in namespace ‘std’ does not name a type
This is the only error - and here is a (truncated) Conf.cpp.
C++ Syntax (Toggle Plain Text)
#ifndef Conf_H #include "Conf.h" #endif #include <string.h> #include "iniparser/iniparser.h" std::string Conf::getString(const char* name) {/* This is the line causing the error */ std::string rtn; rtn = string(iniparser_getstring(this->file, name)); return rtn; }
Line 33 as shown in the code sample is the definition of the function returning a string.
I've tried combinations of using std::string, but each time it states something similar "string does not name a type", "std::string has not been declared" etc..
Any suggestions would be most helpful.
Thanks,
PC_Nerd
> #include <string.h>
This is the old C-style header
Try
#include <string>
#ifndef Conf_H
#include "Conf.h"
#endif
Normally, the header include guards go inside the header file itself.
This is the old C-style header
Try
#include <string>
#ifndef Conf_H
#include "Conf.h"
#endif
Normally, the header include guards go inside the header file itself.
Last edited by Salem; Jul 13th, 2009 at 1:32 am.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
--
If your code lacks code tags, you will be IGNORED
--
If your code lacks code tags, you will be IGNORED
•
•
Join Date: Nov 2008
Posts: 410
Reputation:
Solved Threads: 77
Using gcc,
You include that when you are using code that does not use the std::strcpy form but you want to just write
So if you have not included
So in answer to the question you pose, yes you do need to add
#include <string.h> , provides a back-compatability system for stuff likeusing std::memcpy; etc... You include that when you are using code that does not use the std::strcpy form but you want to just write
strcpy(...) . Since you almost never want using namespace std; it is a nice half-way house, for importing c like code.So if you have not included
#include <string> , you have only a forward declaration for std::string. Hence the error. [Note that gcc use to include <string> in a lot of other includes, but they have been moving towards a independent #include system, so as you go up the version number you need to be more exact on you #include's. This means that although your code gets slightly longer your compile time goes down. So in answer to the question you pose, yes you do need to add
#include <string> BUT you may ALSO need #include <string.h> Last edited by StuXYZ; Jul 13th, 2009 at 5:03 pm.
experience is the most expensive way to learn anything
![]() |
Similar Threads
- using namespace std problem (C++)
- Switch Statement with String (C++)
- C++ enumerated data type help (C++)
- invalid initialisation of reference of type 'double& ' (C++)
- no matching function for call to 'strcmp(std::string&, std::string&)' (C++)
- How to improve program with string compairing? (C++)
- help with namespace error (C++)
Other Threads in the C++ Forum
- Previous Thread: Newbie Question
- Next Thread: create a 'virtual microphone' driver
Views: 2528 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm array arrays assignment basic beginner binary c++ c/c++ calculator char class classes code command compile compiler console constructor conversion convert count delete desktop dll dynamic encryption error file files fstream function functions game givemetehcodez graph gui homework http i/o iamthwee input int lazy linker list loop loops math matrix member memory multidimensional network newbie number numbers object objects opengl operator output parameter pointer pointers problem program programming project random read recursion recursive reference simple sort sorting spoonfeeding string strings struct student studio template templates text time tree undefined variable vc++ vector video visual visualstudio void win32 window windows winsock






