Error String 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 error string in namespace std does not name a type the company Business Learn more about hiring developers or posting ads with us Stack Overflow
Error String Does Not Name A Type C++
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 error âstringâ does not name a type million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up C++ errors: ‘string’ does not name a type up vote 2 down vote favorite 1 when I compile the
String Does Not Name A Type Code Blocks
following files, I've got the error: ECArgs.h:36:3: error: ‘string’ does not name a type ECArgs.h:36: ECString value(char c); Could somebody give me any hints for the error? ECArgs.h #include #include "ECString.h" class ECArgs { public: ECArgs(int argc, char *argv[]); int nargs() { return nargs_; } bool isset(char c); ECString value(char c); ECString arg(int n) { return argList[n]; } private: int nargs_; int nopts_; ECString argList[32]; list optList; }; ECString.h #define ECS string does not name a type arduino gnu #if ECS == gnu #include #define ECString string using namespace std; #else #include #define ECString string #endif c++ string compiler-errors share|improve this question edited Mar 4 '13 at 4:34 asked Mar 4 '13 at 4:06 Xing Shi 1,0341725 It's not a "wired" error. It's perfectly reasonable not to recognize a symbol from a non-included header. Also, typedef and using are better solutions for type aliases than #define. –chris Mar 4 '13 at 4:08 @chris What do you mean by non-included header? –Xing Shi Mar 4 '13 at 4:11 If you want to get access to std::string, you need to #include , not #include . –jogojapan Mar 4 '13 at 4:13 Precisely what the answer says. std::string is in and you never include it. Therefore, the compiler is perfectly reasonable in complaining. –chris Mar 4 '13 at 4:13 @chris You are right, thanks. –Xing Shi Mar 4 '13 at 4:34 | show 1 more comment 2 Answers 2 active oldest votes up vote 1 down vote accepted You need to add: #include cstring includes function to manipulate C-style string. This version works: #include #include #if ECS == gnu #include #define ECString string using namespace std; #else #include #
Get Kubuntu Get Xubuntu Get Lubuntu Get UbuntuStudio Get Mythbuntu Get Edubuntu Get Ubuntu-GNOME Get UbuntuKylin Ubuntu Code of Conduct Ubuntu Wiki Community Wiki Other Support Launchpad Answers Ubuntu IRC Support AskUbuntu Official Documentation User Documentation Social Media Facebook Twitter Useful
String Does Not Name A Type In Header File
Links Distrowatch Bugs: Ubuntu PPAs: Ubuntu Web Upd8: Ubuntu OMG! Ubuntu Ubuntu Insights Planet Ubuntu Activity
String Does Not Name A Type Cpp
Page Please read before SSO login Advanced Search Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] [ C++ string does not name a type dev c++ ] Header files not working as expected. Having an Issue With Posting ? Do you want to help us debug the posting issues ? < is the place to report it, thanks ! Page 1 of 2 12 Last http://stackoverflow.com/questions/15194395/c-errors-string-does-not-name-a-type Jump to page: Results 1 to 10 of 15 Thread: [ C++ ] Header files not working as expected. Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode December 16th, 2009 #1 Physical Hook View Profile View Forum Posts Private Message Gee! These Aren't Roasted! Join Date Dec 2009 Beans 131 [ C++ ] Header files not working as expected. main.cpp: Code: #include #include "engine.h" using https://ubuntuforums.org/showthread.php?t=1356546 namespace std; int main(int argc, char *argv[]) { Sample mc; mc.day = "Monday"; mc.month = "January"; mc.year = 2009; return 0; } engine.h: Code: #ifndef ENGINE_H #define ENGINE_H #include struct Sample { string day; string month; int year; }; #endif Code: In file included from main.cpp:3: engine.h:8: error: ‘string’ does not name a type engine.h:9: error: ‘string’ does not name a type main.cpp: In function ‘int main(int, char**)’: main.cpp:11: error: ‘struct Sample’ has no member named ‘day’ main.cpp:12: error: ‘struct Sample’ has no member named ‘month’ What I'm doing wrong ? Adv Reply December 16th, 2009 #2 dwhitney67 View Profile View Forum Posts Private Message Tolerant of Ubuntu Join Date Jun 2007 Location Maryland, US Beans 6,272 DistroKubuntu Re: [ C++ ] Header files not working as expected. You need to qualify the string data types in your header file with the std:: namespace. Do NOT declare a 'using namespace std' in your header file... bad, bad, bad! Btw, good programming practice dictates that you include your project header file(s) (eg. engine.h) before including system header file(s) (eg. iostream). Please examine your main module. Adv Reply December 16th, 2009 #3 Physical Hook View Profile View Forum Posts Private Message Gee! These Aren't Roasted! Join Date Dec 2009 Beans 131 Re: [ C++ ] Header files not working as expected. Oh, ok - works now Thanks for the suggestion about the hea
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 https://www.daniweb.com/programming/software-development/threads/493608/string-does-not-name-a-type those things. And it still does not 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 back after time). I have also traditionally been coding using the old Borland compiler (which works, even if it is ancient, but I like does not the IDE). I have now been trying to come into the 21st century by using 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: does not name 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 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 us