英文:
Incorrect indentation when using an if statement inside a lambda expression
问题
我使用VS2022,粘贴以下示例中的代码会写成:即使您按Ctrl + K + F
进行排序,它也会按如下方式排序。
// 这是我的VS2022代码
// ...
for_each(v.begin(), v.end(), [&evenCount](int n) {
cout << n;
if (n % 2 == 0) {
cout << " 是偶数 " << endl;
++evenCount;
} else {
cout << " 是奇数 " << endl;
}
});
// ...
// 这是MSDN示例代码
// ...
for_each(v.begin(), v.end(), [&evenCount] (int n) {
cout << n;
if (n % 2 == 0) {
cout << " 是偶数 " << endl;
++evenCount;
} else {
cout << " 是奇数 " << endl;
}
});
// ...
如果我在lambda表达式内部使用if语句,自动缩进不正确。不规则。
我的VS2022设置有问题吗?
英文:
I'm using VS2022, and pasting the code from the following example will write: Even if you press Ctrl + K + F
to sort all, it will be sorted like below.
// This code is my VS2022
// ...
for_each(v.begin(), v.end(), [&evenCount](int n) {
cout << n;
if (n % 2 == 0) {
cout << " is even " << endl;
++evenCount;
}
else {
cout << " is odd " << endl;
}
});
// ...
// This code is MSDN example
// ...
for_each(v.begin(), v.end(), [&evenCount] (int n) {
cout << n;
if (n % 2 == 0) {
cout << " is even " << endl;
++evenCount;
} else {
cout << " is odd " << endl;
}
});
// ...
If I use an if statement inside a lambda expression, automatic indentation is not correct. Not regular.
Is something wrong with my VS2022 settings?
答案1
得分: 1
相似的问题已在开发者社区上报告。尝试使用 VS2022 版本 17.5 预览 5.0。
链接: https://developercommunity.visualstudio.com/t/auto-indentaion-not-working-in-the-lambd/10201118
英文:
Similar problems hava been reported on Developer Community. Try VS2022 version 17.5 preview 5.0.
Link: https://developercommunity.visualstudio.com/t/auto-indentaion-not-working-in-the-lambd/10201118
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论