sách gpt4 ăn đã đi

C++:使用循环和变量模式(序列)

In lại Tác giả: Walker 123 更新时间:2023-11-30 03:37:15 27 4
mua khóa gpt4 giày nike

我有一个例程函数process_letter_location(const char& c, string &word)

在我的 main 中,我声明了一系列字符串变量,如下所示:

string sf_1 = "something", sf_2 = "something", sf_3 = "something",
sf_4 = "something";

tôi có một cái字符串词,我这样调用我的例程函数

process_letter_location(word[0], sf_1);
process_letter_location(word[1], sf_2);
process_letter_location(word[2], sf_3);
process_letter_location(word[3], sf_4);

这看起来确实有点乱,但我知道我可以使用循环来调用例程,例如

for(int i=0; i < 4; i++) {
process_letter_location (word[i], ?)
}

但我不太确定我将如何分配第二个参数。这些变量有共同的“sf_”,唯一改变的是数字。无论如何,我可以将这个例程调用合并到循环中吗?如果没有,是否有更好的方法来实现此代码?

如有任何帮助,我们将不胜感激。谢谢

câu trả lời hay nhất

你可以使用数组:

string sf[4] = { "something1", "something2", "something3", "something4"};

然后循环:

for(int i=0; i < 4; i++) {
process_letter_location (word[i], sf[i]);
}

关于C++:使用循环和变量模式(序列),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40279781/

27 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress