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;