Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: expected unqualified-id before ‘.’ token - std :: vector

Tags:

c++

std

vector

Code:

#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;
}

Output:

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

What's the point that I am missing?

like image 977
Aquarius_Girl Avatar asked Mar 26 '26 15:03

Aquarius_Girl


1 Answers

You need to create an actual variable to be added to your vector:

int main ()
{
    coordinate c;
    c.latitude  = latitude;
    c.longitude = longitude;
    previousPoints.push_back (c);
like image 111
YePhIcK Avatar answered Mar 29 '26 04:03

YePhIcK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!