将返回谷发送到C 的数组
Sending the return vale to an array in c++
这是交易的人:
我正在制作一个统计生成器。该程序具有菜单(在此程序中未完全开发,但是我有以前的代码可以使用),它要求一个名称,然后将其存储到partare1。
然后提示它正在生成您的分数。该函数生成CoratesCore()将3个随机数,每个范围1-6,将它们添加在一起并返回总和。
我希望它循环6次,并将总计存储到数组统计中[6]。
然后,我将字符1和数组发送到txt文件,称为trameave.txt。
它每次都保存我输入的任何名称,但是当我打开TXT文件时,我会得到它。我得到这个
对此的任何帮助将不胜感激,
#include <iostream>
#include <cstring>
#include <array>
#include <string>
#include <fstream>
using namespace std;
int GenerateScore();
int main()
{
int Stats[6];
char Selection;
string Character1;
int i;
cout << "Hello, welcome to my character generator. Please select an option" << endl;// Menu Options
cout << "A: Create Character Name and generate stats" << endl;
cout << "B: Display Name and Stats" << endl;
cout << "C: Quit" << endl;
cin >> Selection; // Menu Selection
cout << endl;
do
{
if ( (Selection == 'a') || (Selection == 'A') )// if user selects a, this happens
{
cout << "Welcome, Before you can start your adventures you must name your character." << endl;
cout << "Please enter your a name." << endl;// prompts user to enter a name for their Caracter
cin >> Character1;
cout << "Thank you now lets generate your stats." << endl;
for (i=0; i<6;i++)// I Want this to run the function GenerateScore() 6 times and input each result into the next element of Stats[6]
{
GenerateScore()>> Stats[i];
}
ofstream savecharinfo("charactersave.txt");// saves the Name and the filled array Stats[6] to the charactersave.txt file
if(savecharinfo.is_open())
{
savecharinfo << Character1;
for(int i = 0; Stats[i]; i++)
{
savecharinfo << Stats[i]; //writing numbers of values2 in the file
}
}
else cout << "File could not be opened." << endl;
break;// this is unfinished after this point
}
}
while ( (Selection != 'c') || (Selection == 'C') ); // ends the program if c or C is entered.
system("PAUSE");
return 0;
}
int GenerateScore()
{
int roll1 = rand()%6+2;
int roll2 = rand()%6+2;
int roll3 = rand()%6+2;
int sum;
sum=roll1+roll2+roll3;
return sum;
}
>>
只能用于std::ostream
实现流动行为。
更改
GenerateScore()>> Stats[i];
to
Stats[i] = GenerateScore();
相关文章:
- 为什么 C++ 中的字符数组返回其项目而不是地址?
- C++ bool 数组返回 1 或 0 以外的值
- C++ ostream 从对象数组返回数据
- 类中的重载运算符 [],因此它可以从模板类中的数组返回对象
- 指向对象的指针数组返回jibberish
- 具有基本结构的结构数组返回错误的答案
- 数组返回乐趣 movie_check()
- C++从字符数组返回类型为T的指针
- C++-将数组返回到主函数,并将数组传递给另一个函数
- C++:如何通过异常处理从越界数组返回值
- 整数数组返回类型
- 从字符串流复制到 char * 数组返回为函数参数
- C++函数从对象数组返回对象的副本.这是默认行为吗?
- 8字节数组返回长(C#到C++)
- 向c#数组返回一个字符数组c++
- 从并行数组返回值,并在以后的函数中使用这些值
- 将c++中的浮点数数组返回给Python
- 如何在gsoap中使字符串数组返回值
- 将两个字符相乘并向数组返回int
- C++套接字 - 从结构数组返回单个地址信息