#include
#include
using namespace std;
int main() {
string pyr_string{};
cout << "Enter the string: ";
cin >> pyr_string;
// i represents the rows
// j represents the columns in the rows
for (size_t i{}, int j{1}; i < pyr_string.length(); ++i, j += 2) {
// Display the spaces
for (size_t i{}; i < pyr_string.length() - i; ++i) {
cout << " ";
}
if (i == 0) {
cout << pyr_string.at(i) << endl;
} else {
for (size_t k{}, int index{}; k < j; ++k) {
if (index + 1 > (j / 2)) {
--index;
cout << pyr_string.at(index);
} else {
++index;
cout << pyr_string.at(index);
}
}
cout << endl;
}
}
return 0;
}
当我尝试构建它时,所有这些错误都会出现,并且我尝试更改了一些错误,下面将对此进行解释:
(错误)
Severity Code Description Project File Line Suppression State
Warning C4552 '
Warning C4552 '
Error C2065 'j': undeclared identifier Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
Error C2447 '{': missing function header (old-style formal list?) Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 18
Error C2447 '{': missing function header (old-style formal list?) Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 20
Error C2059 syntax error: ')' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
Error C2059 syntax error: ')' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 15
Error C2059 syntax error: ';' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 16
Error C2059 syntax error: 'else' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 20
Error C2059 syntax error: 'for' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 15
Error C2059 syntax error: 'if' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 18
Error C2059 syntax error: '}' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 32
Error C2059 syntax error: '}' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 34
Error C2143 syntax error: missing ')' before ';' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 15
Error C2143 syntax error: missing ';' before '{' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
Error C2143 syntax error: missing ';' before '{' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 15
Error C2143 syntax error: missing ';' before '{' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 18
Error C2143 syntax error: missing ';' before '{' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 20
Error C2143 syntax error: missing ';' before '}' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
Error C2143 syntax error: missing ';' before '}' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 32
Error C2143 syntax error: missing ';' before '}' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 34
Error C2062 type 'int' unexpected Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
我是c语言的新手,这是我第一次遇到这么多错误,尽管我知道由于有问题的原因,大多数错误只是一个链条,所以我决定执行以下操作:
for (size_t i{}, int j{1}; i < pyr_string.length(); ++i, j += 2) {
// Display the spaces
continue;
}
和错误只是:
Severity Code Description Project File Line Suppression State
Warning C4552 '
Error C2065 'j': undeclared identifier Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
Error C2059 syntax error: ')' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
Error C2059 syntax error: 'continue' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 15
Error C2059 syntax error: 'return' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 18
Error C2059 syntax error: '}' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 19
Error C2143 syntax error: missing ';' before '{' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
Error C2143 syntax error: missing ';' before '}' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
Error C2143 syntax error: missing ';' before '}' Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 19
Error C2062 type 'int' unexpected Testing D:\VisualStudioRepos\source\repos\Section10\Testing\main.cpp 13
我真的很困惑,不知道该怎么办,我尝试将“ int j {1};”更改为“ size_t j {1};”,然后这也不起作用,并且如果我遇到另一个错误记住正确,我不知道我在做什么错,我在网上搜索了如何将多个语句放入for循环参数中,并且他们做了同样的事情,将逗号放在中间,然后执行了他们想做的下一条语句。