> For the complete documentation index, see [llms.txt](https://mr-poston-1.gitbook.io/c++/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mr-poston-1.gitbook.io/c++/2.-going-beyond-the-basics/2.3-structs/2.3.3-using-structs-line-length.md).

# 2.3.3 Using Structs: Line Length

Structs can be used like any other variable, so it is possible to do many things with them and use them in other data structures.

### Using Structs with Vectors

A good example of extending structs is to use them in a vector. Since a struct is like any other variable, you can create a vector by using the struct name as a type. For example, given the point struct:

```
struct point {
    int x, y;
};
```

You can create and access elements like this:

```
vector<point> points;
point p1;
p1.x = 5;
p1.y = 10;
points.push_back(p1);

// Print x, y
cout << points[0].x << ", " << endl;
```

Notice that you still use the `[ ]` operator then the `.` to acess the vector element and member respectively.

### Other Examples

In thi example, you will see other extensions of structs. As you look through this example, take note of the following:

* The `point` struct is used as a variable type in the `line` struct member definition. This is possible as long as the point struct is defined before the line struct
* The `getPoint` function uses the `point` struct as a return type
* The `lineLength` function needs to access a `point` coordinate from a given line. It does this by stacking the dot variables, i.e. `line.point.x`
* This example uses the `pow` function from the `cmath` library to see more functions from the `cmath` library, you can Google ‘c++ cmath’, or follow this [link](https://www.cplusplus.com/reference/cmath/).

### [Try This Example](https://replit.com/@Poston/233-Using-Structs-Line-Length#main.cpp)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mr-poston-1.gitbook.io/c++/2.-going-beyond-the-basics/2.3-structs/2.3.3-using-structs-line-length.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
