c++ - 错误:预期在 ‘.’ token 之前的不合格 ID - std::vector

标签 c++ vector std

代码:

#include <vector>
#include <iostream>

typedef struct
{
    std :: string latitude;
    std :: string longitude;
} coordinate;

std :: vector <coordinate> previousPoints;

int main ()
{
    coordinate.latitude  = latitude;
    coordinate.longitude = longitude;
    previousPoints.push_back (coordinate);

    return 0;
}

输出:

anisha@linux-y3pi:~> g++ -Wall demo.cpp
demo.cpp: In function ‘int main()’:
demo.cpp:14:12: error: expected unqualified-id before ‘.’ token
demo.cpp:15:12: error: expected unqualified-id before ‘.’ token
demo.cpp:16:38: error: expected primary-expression before ‘)’ token

我错过了什么?

最佳答案

您需要创建一个实际变量以添加到您的 vector 中:

int main ()
{
    coordinate c;
    c.latitude  = latitude;
    c.longitude = longitude;
    previousPoints.push_back (c);

关于c++ - 错误:预期在 ‘.’ token 之前的不合格 ID - std::vector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11808162/

相关文章:

c++ - HippoMocks - 在 "ExpectCallFunc"之后使用 "NeverCallFunc"来实现相同的功能会导致意外的 "HippoMocks::ExpectationException"

c++ - 为 iOS7 编译 BlueZ?

C++ constexpr 关键字放置

r - 在空白处分割字符串向量

c++ - 在 vector 之间使用 std::swap 还是 vector::swap?

c++ - 实时音频,快速循环中的临时缓冲区,不同的方法

c++ - std::sqrt() 函数如何工作?

c++ - 相对于结束迭代器的解引用

c++ - 虽然循环不退出,即使它应该

c++ - 为什么我不能将这个比较函数作为模板参数传递?