我能够得到一个干净的编译,直到我决定使用这种技术输入信息。一旦我克服了这个障碍,我将能够尝试各种场景并测试代码。
#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 ----
}
答案 0 :(得分:2)
您已声明了结构类型,但未声明结构变量。您应该按如下方式更改代码:
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;