gpt4 book ai didi

c++ - 如何构造字符数组

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:24:31 26 4
gpt4 key购买 nike

我有以下代码试图枚举字符串。

#include <string>
#include <iostream>

using namespace std;

string base = "000";
char values[] = {'0', '1', '2', '3' }; // Error Here

for (int i = 0; i < base.length(); ++i)
{
for (int j = 0; j < countof(values); ++j)
{
if (base[i] != values[j])
{
string copy = base;
copy[i] = values[j];
cout << copy << endl;

for (int k = i+1; k < base.length(); ++k)
{
for (int l = 0; l < countof(values); ++l)
{
if (copy[k] != values[l])
{
string copy2 = copy;
copy[k] = values[l];
cout << copy2 << endl;
}
}
}
}
}
}

但是怎么编译就报错了:

test.cc:9: error: expected unqualified-id before 'for'
test.cc:9: error: expected constructor, destructor, or type conversion before '<' token
test.cc:9: error: expected unqualified-id before '++' token

最佳答案

错误实际上在以下行中,在 for 循环中:您的代码需要包含在某种函数中,很可能是 int main(void)

关于c++ - 如何构造字符数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/684191/

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