通过build_native.py返回编译 cocos2d-x:"to_string"未在此范围内声明
Compiling cocos2d-x via build_native.py returns: 'to_string' was not declared in this scope
我试图通过build_native.py
脚本为Android构建一个cocos2d-x 3.0(稳定)项目,但当一个类使用std::to_string
(或std::stoi
)函数时,它会挂起。在Xcode下构建项目完全没有问题,只是命令行编译失败了。
我已经在所有使用这些函数的类中导入了<string>
,但是没有成功。我还像这样修改了Application.mk
文件:
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCOCOS2D_DEBUG=0 -std=c++11 -Wno-literal-suffix -fsigned-char
添加-std=c++11
标志,以确保使用c++ 11版本编译项目。
我还需要做些什么吗?
多在这个线程之后,我决定包括这个:
#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
string to_string(int t) {
ostringstream os;
os << t;
return os.str();
}
#endif
在我的头,因为我只是使用to_string
与整数输入。这不是一个好的解决方案,但效果很好……但是当它找到stoi
函数时,编译器会挂起。
我最终使用了这段代码:
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
string to_string(int t) {
ostringstream os;
os << t;
return os.str();
}
int stoi(const string myString) {
return atoi(myString.c_str());
}
#endif
尝试使用atoi代替stoi。虽然atoi在错误时返回零,但它可以与命令行编译一起工作
你可以通过使用sstream库来完成int到STR的转换过程,它有些长,但它有效:
#include <sstream>
std::stringstream myStringStream ;
myStringStream << myInteger;
myString = myStringStream.str();
相关文章:
- C++:如何将 unix 时间的字符串转换为 *tm?(使用时间错误:"cannot convert 'String' to 'tm*' ")
- OpenCV undefined reference to 'cv::imread(cv::String const&, int)'
- std::time_point from and to std::string
- "No suitable conversion function from 'std::string' to 'const char *' exists"
- 如果子类中没有构造函数方法,则错误"no matching function for call to 'LGame::LGame(String&)'"
- 使用词法强制转换在'string to double'中设置双精度变量的精度
- 在 Lua 中加载 C++ 模块时'Attempt to index a string value'错误
- std::string to std::regex
- "How to pass String value in between URL in C/C++?"
- "conversion from void to non scalar type string"是什么意思?
- 我收到一个" conversion from ‘std::string (*)[50]’ to non-scalar type ‘std::string’ requested"错误,似乎无法修复它
- 如何防止从函数生成的字符串中使用科学记数法"number to string"?
- hwProfileInfo.szHwProfileGuid to String?
- 编写我自己的字符串类"reference to ‘string’ is ambiguous"但出现编译错误
- c++ stringstream to ostream to string
- How cin to string?
- C++ *string convert to string
- Round Double and Cast to String
- Regex-ed value to String
- vector string to string (or c_string) to lpszString