C++ 游戏1程序错误(使用名称到年龄的字符串位置1作为猜测游戏编号)

C++ 游戏1程序错误(使用名称到年龄的字符串位置1作为猜测游戏编号),c++,C++,我在这段代码中有一些错误 我只想做一个我认为会起作用的函数 当然,由于这个原因,程序没有运行,因为这个错误 (代码中有注释,解释了什么东西可以做什么。) 错误(活动)E1345空初始值设定项对于具有未指定边界的数组无效 错误C2040“名称”:“std::string[]”与“std::string”的间接寻址级别不同 错误C2466无法分配常量大小为0的数组 这些错误是由以下代码引起的: #include <iostream> #include <string> #in

我在这段代码中有一些错误

我只想做一个我认为会起作用的函数

当然,由于这个原因,程序没有运行,因为这个错误

(代码中有注释,解释了什么东西可以做什么。)

错误(活动)E1345空初始值设定项对于具有未指定边界的数组无效

错误C2040“名称”:“std::string[]”与“std::string”的间接寻址级别不同

错误C2466无法分配常量大小为0的数组

这些错误是由以下代码引起的:

#include <iostream>
#include <string>
#include <time.h>
using namespace std;

int main()
{ 
string name; //your name
string age; //your age
string pueblo; //Where you live

//The rest is using "getline(cin, those strings)" for each one.

//Until... this part...

srand(time(NULL)); //Just activating the random seed
        int i = 0;
        string name[] = {};
        string hr;
        int n = rand() % 1;
        hr = name[n]; //this part is nonsensical

        int Game1Attempt = 0; //The tries

        cout << "Juego 1\n";
        cout << "Tienes 3 oportunidades para adivinar el numero. El numero esta entre " << name[1] << " y tu edad mas las letras de tu nombre.\n";
/*Translation:
Game 1:
You have 3 tries to figure the number out. 
The number is between the "Position 1 of your string name" and your "string age" plus the letters of your string name*/

        while (Game1Attempt < 3) //Self-Explainatory
        {
            /*Here I'm trying to get the user input to guess what position
    Of those strings, is the number you are trying to figure out for example
      Your Name[1] and Age 10 + Letters of Your Name*/
            cout << "Intento 1:";
            cin >> n;
            cout << "\nIntento 2:";
            cin >> n;
            cout << "\nIntento 3:";
            cin >> n;
        }
        if (Game1Attempt == 3)
            cout << "The number was " << n << endl; 
           //Lastly if user tried 3 times, ends with revealing what number was so... (Position 1 from Name to Age plus Letters of Name) I still don't get it...
#包括
#包括
#包括
使用名称空间std;
int main()
{ 
string name;//您的名字
字符串年龄;//您的年龄
string pueblo;//您住在哪里
//其余的是对每个字符串使用“getline(cin,那些字符串)”。
//直到…这部分。。。
srand(time(NULL));//仅激活随机种子
int i=0;
字符串名称[]={};
字符串hr;
int n=rand()%1;
hr=name[n];//这部分毫无意义
int Game1Attempt=0;//尝试
你能先做吗

string name;
它将变量
name
定义为
string
对象,并默认构造它

那你呢

string name[] = {};
这将尝试将变量
name
重新定义为大小未知的数组。这是不允许的,数组必须有大小。而且看起来您并不真正希望
name
是数组,而是单个
string
对象。因此,只需删除重新定义的行即可

如果你想拥有一个由
字符串
对象组成的数组,那么你需要给它一个大小。或者更好的是用于一个动态大小的“数组”。哦,你不应该把它命名为同一范围内的另一个变量。

首先你要这样做

string name;
它将变量
name
定义为
string
对象,并默认构造它

那你呢

string name[] = {};
这将尝试将变量
name
重新定义为大小未知的数组。这是不允许的,数组必须有大小。而且看起来您并不真正希望
name
是数组,而是单个
string
对象。因此,只需删除重新定义的行即可


如果你想拥有一个由
字符串
对象组成的数组,那么你需要给它一个大小。或者更好的是用于一个动态大小的“数组”。哦,你不应该把它命名为同一范围内的另一个变量。

你得到了
名称
字符串名称;
字符串名称[]={};
您得到了
名称的两个定义:
字符串名称;
字符串名称[]={};