Error String In Class Does Not Name A Type
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or string in namespace std does not name a type posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss
String Does Not Name A Type Arduino
Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes error does not name a type c++ a minute: Sign up Why am I getting string does not name a type Error? up vote 41 down vote favorite 9 game.cpp #include #include #include #include "game.h" #include "board.h" #include "piece.h" using namespace std; game.h #ifndef 'exception' in namespace 'std' does not name a type GAME_H #define GAME_H #include class Game { private: string white; string black; string title; public: Game(istream&, ostream&); void display(colour, short); }; #endif The error is: game.h:8 error: 'string' does not name a type game.h:9 error: 'string' does not name a type c++ string std share|improve this question edited Jul 29 at 4:44 gsamaras 20.2k163575 asked Apr 3 '11 at 4:54 Steven 3012512 add a comment| 4 Answers 4 active oldest votes up vote 64 down vote accepted Your using declaration is
_dev_t Does Not Name A Type
in game.cpp, not game.h where you actually declare string variables. You intended to put using namespace std; into the header, above the lines that use string, which would let those lines find the string type defined in the std namespace. As others have pointed out, this is not good practice in headers -- everyone who includes that header will also involuntarily hit the using line and import std into their namespace; the right solution is to change those lines to use std::string instead share|improve this answer edited Apr 4 '11 at 14:54 answered Apr 3 '11 at 4:55 Michael Mrozek 72.1k11125136 6 @Michael Mrozek, @Steven: Moving using namespace std; into the header is a despicable act. Advising it doubly-so! –Johnsyweb Apr 3 '11 at 7:22 1 @Johnsyweb Personally I hate using namespace altogether, but it's clearly what he intended to do –Michael Mrozek Apr 3 '11 at 18:10 2 @Michael: All the more reason to discourage him! –Johnsyweb Apr 3 '11 at 22:54 1 From the book C++ Coding Standards (Sutter) - "Don't write namespace usings in a header file or before an #include" It is not about style but about danger. –Eddy Pronk Apr 4 '11 at 13:45 9 @Johnsyweb I hate when I search the internet for a problem, see someone who's asked the same question, and all the answers are "no, don't do that" -- I answer the question that was asked. I sho
my .cpp, but i keep getting the error 'string' does error: ‘vector’ does not name a type not name a type when i try to compile! why?!? fatal error: string: no such file or directory any ideas? i thought #include was what INCLUDED the library for using strings?? this is
Error Cout Was Not Declared In This Scope
in a header file attached to a .cpp that i'm using to store classes and class member functions to be used by the client program, does that http://stackoverflow.com/questions/5527665/why-am-i-getting-string-does-not-name-a-type-error make a difference? i'll throw up the part of my code where it says i have this problem..: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include #include #include #include #include #include #include #include //using namespace std; //******************************************************************** //CLASSES //******************************************************************** //******************************************************************** //Class InvBin //******************************************************************** class InvBin { private: string description; // item http://www.cplusplus.com/forum/general/64054/ name int qty; // Quantity of items // in this bin and the error says: 'string' does not name a type please excuse the LIST of includes... my prof told me that if you don't use it the compiler ignores it so it's not a bad idea to just make a master list, so you don't have to keep remembering to type in the ones you need... Last edited on Mar 8, 2012 at 9:47pm UTC Mar 8, 2012 at 9:47pm UTC LB (13378) Change "string" to "std::string" Most likely you did not mean to comment out line 12. Also, what your professor told you only applies when you have optimizations on - in debug mode (no optimizations) it does not apply. Last edited on Mar 8, 2012 at 9:49pm UTC Mar 8, 2012 at 9:53pm UTC C Theroux (23) oh! you're right on line 12.. and if i uncomment it, i shouldn't have any proble
at least 100 times on the net. But in every case, it seems to be an error of #including instead of or metioning string instead of std::string. But, I've done all those things. And it still does not https://www.daniweb.com/programming/software-development/threads/493608/string-does-not-name-a-type work. By way of background: I am a LONG time newbie C++ programmer (meaning that I write code in spurts and then not at all for several years, which means that whenever I advance beyond newbie status, I slide http://arduino.stackexchange.com/questions/21734/cant-compile-my-library-because-string-does-not-name-a-type back after time). I have also traditionally been coding using the old Borland compiler (which works, even if it is ancient, but I like the IDE). I have now been trying to come into the 21st century by using does not gnu c++ (g++ and mingw). The code problem that I am presenting compiles using the Borland compiler, but gives me the error message only when I try to compile with g++. The problem code: #ifndef ERRORHANDLER_H #define ERRORHANDLER_H #define DOS #include #include #include #include #include #include class ErrorReport { private: std::string logfilename; public: void set (const std::string name) {logfilename=name;}; std::string file() const {return logfilename;}; std::string GetNow() const { std::string now; char does not name date [10]; _strdate(date); char time [10]; _strtime(time); now= date; now+= " "; now+= time; now+= " "; return now; }; . . . You can see I use std::string and have this header protected with an #ifndef envelope. I am not using namespace in the header, which people tell me is a bad thing to do. So, any suggestions?? Thanks for your time. c++ string tgreiner 39 posts since Dec 2008 Community Member 3Contributors 5Replies 21Views 1 YearDiscussion Span 1 Year Ago Last Post by Schol-R-LEA 0 mike_2000_17 2,669 1 Year Ago The C standard headers time.h and stdlib.h should not be used in C++ code. You need to using the C++ versions of these headers, which are included with #include and #include , respectively. Then, any function from these headers must also be prefixed with std:: like all other C++ standard library classes and functions. Then, the _strdate and _strtime functions are not standard C/C++ functions. They are C functions provided by old Microsoft headers (included by time.h), and you should not use them if you want to write portable code (e.g., be able to use another compiler or OS beside Microsoft or Borland). The standard C++ equivalent of that code is this for example (using the strftime function): char buf[100]; /* Print today's date and time, e.g. "Thu Aug 23 14:55:02 2001". */ std::time_t mytime = std::time(NULL); std::strft
a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Arduino beta Questions Tags Users Badges Unanswered Ask Question _ Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Can't compile my library because “String does not name a type” up vote 1 down vote favorite I am writing a small library to move some code out of the arduino sketch and make it reusable. Problem is that it does not compile since "String does not name a type". This is my code (reduced): myESP.h: #ifndef MYESP_H #define MYESP_H #include "Arduino.h" #include #include #include #include #include #include #include class myESP { private: const char* _ssid; const char* _password; const char* _host; public: myESP(); myESP(char * ssid, char * pwd, char * host); String macToStr(const uint8_t* mac); String doGet(String data, String sensor, int duration); }; #endif myESP.cpp: #include #include "Arduino.h" #include "myESP.h" myESP::myESP() {} myESP::myESP(char * ssid, char * pwd, char * host) { _host = host; _password = pwd; _ssid = ssid; } myESP::String macToStr(const uint8_t* mac) { } myESP::String doGet(String data, String sensor, int duration) { } When i try to compile it, I get the following: /Users/lbedogni/Documents/Arduino/libraries/myESP/myESP.cpp:14:1: error: 'String' in 'class myESP' does not name a type myESP::String macToStr(const uint8_t* mac) { /Users/lbedogni/Documents/Arduino/libraries/myESP/myESP.cpp:22:1: error: 'String' in 'class myESP' does not name a type myESP::String doGet(String data, String sensor, int duration) { I have tried to change the order of the imports, change libraries, but still it does not compile. Any idea? library esp8266 share|improve this question asked Mar 12 at 11:24 lbedogni migrated from ele