如何在c++中使用printf打印std::string数组
How to print std::string array with printf in c++?
我正在尝试用printf打印std::string,这是我的代码。但它不会打印我指定的字符串。
头文件
#include "cocos2d.h"
#include <iostream>
class Cards : public cocos2d::CCLayer{
public:
virtual bool init();
virtual void load();
std::string TotalCards[52];
}
#include "Cards.h"
bool Cards::init(){
if ( !CCLayer::init() ) {
return false;
}
TotalCards[0] = "ClubsA";
TotalCards[1] = "HeartsB";
TotalCards[2] = "Diamonds4";
return true;
}
void Cards::load(){
printf("Hey I am HEREn");
for (int i=0 ; i<3; i++) {
printf("CARD NAME %sn", TotalCards[i].c_str());
}
它只打印
卡名
卡名
卡片名称
在调用Cards::load
之前,请确保调用了Cards::init()
并返回true。如果Cards::init()
未被调用,或者返回false,则Cards::load
访问的数组将由三个空字符串组成。
相关文章:
- 如何使用 std::variant 打印地图键/值?
- 为什么 std::cout 打印浮点数、双精度和长双精度到相同的小数精度?
- 如何打印大于"无符号长长"的"std::bitset"的十进制值?
- main() 中的 std::cout 在调试期间不会在调试控制台中打印任何内容
- 重载 std::字符串运算符+ 用于打印枚举名称
- 在 c++ 中以十六进制格式打印无符号字符(BYTE).使用 std::cout
- std::带有颜色和标题的 clog 包装器无法正确打印整数
- 为什么这个程序接受整数和字母数字输入并打印它们? C++ 中的 std::string 也采用整数值吗?
- std::cout 在打印变量与函数表达式时的行为不同
- 使用 std::for_each 迭代和打印 std::map
- 有条件的打印和计数在 std::map 上有限制
- 在瓦尔格林德的泄漏摘要中使用 std::ios::sync_with_stdio(fasle) 打印时获取"still reachable"
- 如何在c++中打印原始std::string/c样式的字符串
- 打印空指针时,std::cout 可以打印 "NULL" 而不是 0 吗?
- C++ - 使用 std::list,如何打印对象的私有成员的链接列表?
- 打印一个带有静态 int 的函数,有一个 std::cout 和多个 std::cout 有什么区别?
- 使用带有 std::cout 的单引号打印字符串实际上打印了数字
- Std::copy 和 std::ostream_iterator 使用重载函数打印值
- 为什么 std::hex 没有特别用字符打印为十六进制?
- std::打印换行时字符串清空