在决定使用此技术输入信息之前,我可以进行干净的编译。一旦克服了这一障碍,我将能够尝试各种方案并测试代码。
#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_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;
关于c++ - 我有一个变量,它是结构中的许多变量,我想向其中读取信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10499828/