如何迭代 char 的元素,以便输出带有 <cstring> 中的字符串? [已关闭]

问题描述 投票:0回答:1

示例: 字符符号 = ".,-"; 字符stringg =“哈哈”;

输出: 哈哈, 哈哈。 哈哈-

如何使用 来实现这一点?

穿过&没出来 理想的。直舱壁

llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll 哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈

c++ c-strings
1个回答
0
投票
#include <iostream> #include <string> int main() { std::string string1 = ",.;"; std::string string2 = "abc"; std::string output; // Iterate over each character in string1 for (char ch : string1) { // Concatenate string2 with the current character from string1 output += string2 + ch; } // Print the final output std::cout << output << std::endl; return 0; }
    
© www.soinside.com 2019 - 2024. All rights reserved.