c语言错误代码c2059syntax,我的代码遇到了7个错误,我不确定为什么

#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循环参数中,并且他们做了同样的事情,将逗号放在中间,然后执行了他们想做的下一条语句。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值