error: no type named 'string' in namespace 'std'; did you mean 'std::string'? [3]

在使用Cocos2d进行开发时,遇到错误:notypenamed'string'innamespace'std';通过引入命名空间std解决。本文详细介绍了如何在Cocos2d中正确使用std命名空间,并提供了相关代码示例。

今天在弄cocos2d的时候 看了一篇博客 想试着弄一下,遇到了问题, error: no type named 'string' in namespace 'std'; did you mean 'std::string'? [3]

具体的代码如下

CCUserDefault::sharedUserDefault()->setStringForKey("string", "value1");
    CCUserDefault::sharedUserDefault()->setIntegerForKey("integer", 10);
    CCUserDefault::sharedUserDefault()->setFloatForKey("float", 2.3f);
    CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.4);
    CCUserDefault::sharedUserDefault()->setBoolForKey("bool", true);
    
    // print value
    
    string ret = CCUserDefault::sharedUserDefault()->getStringForKey("string");
    CCLOG("string is %s", ret.c_str());

心里想,靠,这破玩意声明个字符串怎么还报错,而他们的例子怎么没事,第一反应,没有导入头文件,不过找了找,发现该有的都有啊。于是乎各种百度,最后搞明白了。

要使用命名空间,C++很经典的一个问题,之前在学校的时候就遇到过这个问题。mark一下,继续搞!

using namespace std;                //使用名字空间(使用所有)

ClassInheritancePlugin.cpp:20:40: error: no member named &#39;getTypeLoc&#39; in &#39;clang::CXXBaseSpecifier&#39; 20 | TypeLoc BaseLoc = Base.getTypeLoc(); | ~~~~ ^ ClassInheritancePlugin.cpp:50:80: error: non-virtual member function marked &#39;override&#39; hides virtual member function 50 | bool ParseArgs(CompilerInstance &CI, const std::vector<std::string> &args) override { | ^ /usr/local/include/clang/Frontend/FrontendAction.h:275:16: note: hidden overloaded virtual function &#39;clang::PluginASTAction::ParseArgs&#39; declared here: type mismatch at 1st parameter (&#39;const CompilerInstance &&#39; vs &#39;CompilerInstance &&#39;) 275 | virtual bool ParseArgs(const CompilerInstance &CI, | ^ ClassInheritancePlugin.cpp:55:18: error: no type named &#39;PassPluginLibraryInfo&#39; in namespace &#39;llvm&#39; 55 | extern "C" llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK | ~~~~~~^ ClassInheritancePlugin.cpp:57:13: error: use of undeclared identifier &#39;LLVM_PLUGIN_API_VERSION&#39; 57 | return {LLVM_PLUGIN_API_VERSION, "ClassInheritancePlugin", LLVM_VERSION_STRING, | ^ ClassInheritancePlugin.cpp:58:16: error: unknown type name &#39;PassBuilder&#39;; did you mean &#39;llvm::PassBuilder&#39;? 58 | [](PassBuilder &PB) { | ^~~~~~~~~~~ | llvm::PassBuilder /usr/local/include/clang/Basic/CodeGenOptions.h:33:7: note: &#39;llvm::PassBuilder&#39; declared here 33 | class PassBuilder; | ^ ClassInheritancePlugin.cpp:59:19: error: member access into incomplete type &#39;llvm::PassBuilder&#39; 59 | PB.registerPlugin("ClassInheritancePlugin", | ^ /usr/local/include/clang/Basic/CodeGenOptions.h:33:7: note: forward declaration of &#39;llvm::PassBuilder&#39; 33 | class PassBuilder; | ^ ClassInheritancePlugin.cpp:60:44: error: use of undeclared identifier &#39;PassBuilder&#39;; did you mean &#39;llvm::PassBuilder&#39;? 60 | [](const PassBuilder::PipelineParsingContext &, | ^~~~~~~~~~~ | llvm::PassBuilder /usr/local/include/clang/Basic/CodeGenOptions.h:33:7: note: &#39;llvm::PassBuilder&#39; declared here 33 | class PassBuilder; | ^ ClassInheritancePlugin.cpp:60:44: error: incomplete type &#39;llvm::PassBuilder&#39; named in nested name specifier 60 | [](const PassBuilder::PipelineParsingContext &, | ^~~~~~~~~~~~~ /usr/local/include/clang/Basic/CodeGenOptions.h:33:7: note: forward declaration of &#39;llvm::PassBuilder&#39; 33 | class PassBuilder; | ^ ClassInheritancePlugin.cpp:61:54: error: use of undeclared identifier &#39;Pass&#39; 61 | SmallVectorImpl<Pass *> &) { | ^ ClassInheritancePlugin.cpp:61:60: error: expected expression 61 | SmallVectorImpl<Pass *> &) { | ^ ClassInheritancePlugin.cpp:66:12: error: unknown type name &#39;PassPlugin&#39; 66 | extern "C" PassPlugin *createPassPlugin() { | ^ ClassInheritancePlugin.cpp:67:16: error: unknown type name &#39;PassPlugin&#39; 67 | return new PassPlugin(createClassInheritanceAction()); | ^ 12 errors generated.
08-07
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值