gpt4 book ai didi

c++ - 在 Const char string[] 上使用字符串函数

转载 作者:行者123 更新时间:2023-11-30 05:36:00 29 4
gpt4 key购买 nike

我正在尝试创建一个方法,该方法将从用户那里获取参数 const char string[]。这个参数。然后将通过 for 循环逐字符输出到屏幕,直到字符串达到其长度。

我需要知道字符串的长度才能让我的循环工作。例如,如果长度为 6,则循环应运行 6 次,并在显示器上显示 6 个字符。

我会为此使用 foreach 循环,但我实际上是在 GBA 环境中,由于某些原因每个循环都无法正确编译。所以我尝试使用 .strlen() 来获取字符串的长度。

但是,我不能使用 .strlen() 方法,因为我的 const char string[] 不是字符串。

考虑到以上所有内容,如何在以下代码中使用 .strlen() 方法?:

void DrawText(int x, int y, const char string[])
{


for(int i = 0; i < string.strlen(); i++)
{
SetTile(0, x + i, y, 70);
}
}

最佳答案

您可以使用 cstring header 中的 std::strlen(string),但前提是 string 指向以 null 结尾的 char 数组。

关于c++ - 在 Const char string[] 上使用字符串函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33655608/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com