我是 C++ 的新手,我的问题是如何将循环周期中的数据存储到数组中,然后打印出来? 我需要再做一个循环吗?如果是这样,我该怎么做?另外,如果我的要求是可能的,那么每次我重新运行编译器时,上面的数组都会被重写或删除(希望如此)吗?
int getcard()
{
srand((unsigned)time(0));
int x;
string mix[10];
string h;
do
{
for (int index = 0; index < 10; index++)
{
x = rand() % 18;
h = master[x];
cout << h << endl;
}
mix[10] = h;
}
while (false);
return 0;
}
最佳答案
这段代码创建了一个字符串数组,将其元素初始化为“字符串”并将其打印出来。
string array[10];
for (int i=0; i<10; i++){
array[i] = "string";
}
for (int i=0; i<10; i++){
cout<<array[i] <<" ";
}
你应该尝试一些类似的东西。
关于c++ - 将数据从循环存储到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13321996/