Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我有一个变量,是结构中许多变量中的一个,我想把信息读入其中_C++_Struct_User Input - Fatal编程技术网

C++ 我有一个变量,是结构中许多变量中的一个,我想把信息读入其中

C++ 我有一个变量,是结构中许多变量中的一个,我想把信息读入其中,c++,struct,user-input,C++,Struct,User Input,我能够得到一个干净的编译,直到我决定使用这种技术输入信息。一旦我越过这个障碍,我将能够尝试各种场景并测试代码 #include <iostream> #include <sstream> #include <string> int main (void) { float test; /* a simple variable */ struct seTup_backS_Format /

我能够得到一个干净的编译,直到我决定使用这种技术输入信息。一旦我越过这个障碍,我将能够尝试各种场景并测试代码

#include <iostream>
#include <sstream>
#include <string>

int main (void)
   {
    float test;                     /* a simple variable */

    struct seTup_backS_Format       /* the structure has about 30 variables */
       {
        float grnd_Elev;
        int many;     
       };

    string line;                    /* a string */

    getline(cin,line);
    stringstream (line) >> test;    // no problem

                                    // when I try

    stringsteam (line) >> seTup_backS_Format.grnd_Elev;    

               // the compiler says, expected primary-expression before '.' token ----

   }
#包括
#包括
#包括
内部主(空)
{
浮点测试;/*一个简单变量*/
struct seTup\u backS\u Format/*该结构大约有30个变量*/
{
浮式起重机;
int多;
};
字符串行;/*字符串*/
getline(cin,line);
stringstream(line)>>测试;//没问题
//当我尝试
stringsteam(line)>>设置\u backS\u Format.grnd\u Elev;
//编译器说,应在“.”标记之前使用主表达式----
}

您已声明结构类型,但未声明结构变量。您应该按如下方式更改代码:

struct seTup_backS_Format       /* the structure has about 30 variables */
   {
    float grnd_Elev;
    int many;     
   } setup; // Declare a variable "setup" of type "struct seTup_backS_Format"

string line;                    /* a string */

getline(cin,line);
stringstream (line) >> test;    // no problem

                                // when I try

stringsteam (line) >> setup.grnd_Elev;