C++ kodu çalışmıyor

Katılım
25 Ağustos 2020
Mesajlar
678
Çözümler
5
Yazdığım C++ kodu g++ ile compile ettikten sonra çalışıyor fakat kaynak kod üzerinde değişiklik yapıp tekrar compile ediip deneyince çoğu zaman çalışmıyor.
Çalışan kod:

C++:
#include <iostream>
#include <fstream>
#include <string>

int main()
{
 int good = 0;
 int bad = 0;

 std::string cache;

 const int threshold = 10;

 std::string data1[100];
 std::string data2[100];

 std::fstream item("merhaba1.compressed");

 for (int index = 0; index <= 100; index++)
 {
 getline(item ,cache);
 data1[index] = cache;
 }

 std::fstream item2("merhaba2.compressed");

 for (int index = 0; index <= 100; index++)
 {
 getline(item2 ,cache);
 data2[index] = cache;
 }

 cache = "";
 item.close();
 item2.close();
 std::cout << data1[2] << "\n";
 std::cout << data2[5];
 std::cin >> cache;
 return 0;
}

Değişiklik yapınca çalışmayan kod:

C++:
#include <iostream>
#include <fstream>
#include <string>

int main()
{
 int good = 0;
 int bad = 0;

 std::string cache;

 const int threshold = 10;

 std::string data1[100];
 std::string data2[100];

 std::ifstream item("merhaba1.compressed");
 std::ifstream item2("merhaba2.compressed");

 for (int index = 0; index <= 100; index++)
 {
 getline(item, cache);
 data1[index] = cache;
 getline(item2, cache);
 data2[index] = cache;
 }

 cache = "";
 item.close();
 item2.close();
 std::cout << data1[1];
 return 0;
}

Ben kendi kodumda saatlerce hata ayıklama yaptıysamda sorunu bulamadım.
 
Sorunu açıklamayı unutmuşum. Cout komutu data1 array'inin indexi verilen değerini yazdırmıyor. Galiba veride bir sıkıntı yok çünkü data[1]'in yerine "hello world" gibi bir string yazında bile çalışmıyor.
 

Yeni konular

Geri
Yukarı