문자열을 열거하려고하는 다음 코드가 있습니다.Howto는 문자 배열을 구성합니다.
#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
나는 가혹한 사람이되고 싶지 않지만 동적 언어를 먼저 배우는 것이 잘못된 이유입니다. 프로그램의 시작점은 명시 적 (C처럼)이거나 암시 적이어야합니다 (예 : Python에서와 같이). – pyon