在c+中输入不同长度的钉扎+;? 我想知道不同长度的字符串,不知道它们的长度,并将它们的字符分布在C++中作为输入。 取字符串数(3)
拿第一根绳子。示例:在c+中输入不同长度的钉扎+;? 我想知道不同长度的字符串,不知道它们的长度,并将它们的字符分布在C++中作为输入。 取字符串数(3),c++,C++,拿第一根绳子。示例:hello,它应该像 a[]={'h','e','l','l','o'} 拿第二根弦 拿第三根弦 要在数组中存储字符串的字符,可以尝试以下操作: string string1 = "Hello"; char a[string1.length()+1]; for (int i = 0; i < string1.length(); i++) { a[i] = string1[i]; } string string1=“你好”; 字符a[string1.lengt
hello
,它应该像
a[]={'h','e','l','l','o'}
要在数组中存储字符串的字符,可以尝试以下操作:
string string1 = "Hello";
char a[string1.length()+1];
for (int i = 0; i < string1.length(); i++)
{
a[i] = string1[i];
}
string string1=“你好”;
字符a[string1.length()+1];
对于(int i=0;i
它将遍历整个字符串,并使用.length()将索引值存储在[]中。如果你有几个字符串,重复这个过程。你能为这个问题发布你的全部代码,并更具体地说明你在步骤4中要完成什么吗?3//字符串的数量---+++-//第一个字符串++++4//第二个字符串-+-+-4//第三个字符串有什么理由不使用std::string吗?@KennyOstrom我是一个初学者,请给我一些帮助正确的方法是使用std::string,而不是将它们放在char数组中。只需将它们添加到std::vectorstring[10];for(int i=0;i>s[i];}for(int j=0;jNow)我想把存储在s[1]中的字符串转换成一个新的字符数组。很抱歉没有像std::string::data()或std::string::c_str()那样清晰?这个答案中a的长度是多少?@kennyOstrom a的长度取决于字符串的长度。