> For the complete documentation index, see [llms.txt](https://docs.yavuzlar.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yavuzlar.org/egitim/c-plus-plus/4.0-veri-yapilari-data-structures/4.9-iterator.md).

# 4.9 Iterator

C++ dilinde iteratörler, bir koleksiyondaki elemanlara erişim sağlamak ve bu elemanlar üzerinde işlem yapmak için kullanılan bir araçtır. Iteratörler, klasik dizi indekslemesi yerine, koleksiyonlar arasında genel bir arayüz sunarak daha esnek bir veri erişimi sağlar. C++ Standard Template Library (STL) içerisinde geniş bir iteratör desteği bulunmaktadır.

#### Iteratörlerin Temel Özellikleri

1. **Genel Erişim**: Iteratörler, diziler, vektörler, listeler gibi farklı veri yapıları üzerinde kullanılabilir.
2. **Dizisel Erişim**: Iteratörler, bir dizi gibi art arda gelen elemanlara erişim sağlar.
3. **Artış ve Azalış**: Iteratörler, üzerinde dolaşmak için artırma (`++`) ve azaltma (`--`) operatörleri ile kullanılabilir.
4. **Kapsamlı Kullanım**: STL içinde yer alan birçok algoritma, iteratörler ile çalışacak şekilde tasarlanmıştır.

#### Iteratör Kullanımı

C++'ta iteratör kullanmak için, genellikle `#include <iterator>` veya ilgili koleksiyon kütüphanesini dahil etmeniz gerekir. Aşağıda iteratörlerin temel kullanımına dair örnekler bulunmaktadır.

**Vektör ile Iteratör Kullanımı**

```cpp
#include <iostream>
#include <vector>

int main() {
    // Bir vektör oluşturma
    std::vector<int> sayilar = {1, 2, 3, 4, 5};

    // Vektör için bir iteratör oluşturma
    std::vector<int>::iterator it;

    // Elemanları yazdırma
    std::cout << "Vektör elemanları: ";
    for (it = sayilar.begin(); it != sayilar.end(); ++it) {
        std::cout << *it << " "; // Dereferans ile elemanı al
    }
    std::cout << std::endl;

    return 0;
}
```

**List ile Iteratör Kullanımı**

```cpp
#include <iostream>
#include <list>

int main() {
    // Bir liste oluşturma
    std::list<std::string> isimler = {"Ali", "Ayşe", "Fatma", "Mehmet"};

    // Liste için bir iteratör oluşturma
    std::list<std::string>::iterator it;

    // Elemanları yazdırma
    std::cout << "Liste elemanları: ";
    for (it = isimler.begin(); it != isimler.end(); ++it) {
        std::cout << *it << " "; // Dereferans ile elemanı al
    }
    std::cout << std::endl;

    return 0;
}
```

#### Reverse Iteratörler

C++'ta tersine iteratörler (reverse iterators), bir koleksiyondaki elemanları ters sırayla dolaşmak için kullanılır.

```cpp
#include <iostream>
#include <vector>

int main() {
    // Bir vektör oluşturma
    std::vector<int> sayilar = {1, 2, 3, 4, 5};

    // Tersine iteratör ile elemanları yazdırma
    std::cout << "Ters sıradaki vektör elemanları: ";
    for (std::vector<int>::reverse_iterator it = sayilar.rbegin(); it != sayilar.rend(); ++it) {
        std::cout << *it << " "; // Dereferans ile elemanı al
    }
    std::cout << std::endl;

    return 0;
}
```

#### Sonuç

C++ iteratörleri, koleksiyonların elemanlarına erişmek ve işlem yapmak için güçlü ve esnek bir araçtır. Farklı veri yapılarında kullanılabilir ve STL algoritmaları ile birlikte etkili bir şekilde çalışır.


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.yavuzlar.org/egitim/c-plus-plus/4.0-veri-yapilari-data-structures/4.9-iterator.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
