CodeBlocks String in Linux Problem

0

Witam jak w temacie mam problem z deklarowaniem zmiennej w stringu.
#include <iostream>
#include <string.h>
struct filmy
{
string tytul;
int rok;
int czas;
}

Błąd :

/home/kicex/Projekty/Struktura_1/main.cpp|5|error: ‘string’ does not name a type|
/home/kicex/Projekty/Struktura_1/main.cpp||In function ‘int main()’:|
/home/kicex/Projekty/Struktura_1/main.cpp|18|error: ‘struct filmy’ has no member named ‘tytul’|
/home/kicex/Projekty/Struktura_1/main.cpp|21|error: ‘struct filmy’ has no member named ‘tytul’|
/home/kicex/Projekty/Struktura_1/main.cpp|24|error: ‘struct filmy’ has no member named ‘tytul’|
/home/kicex/Projekty/Struktura_1/main.cpp|27|error: ‘struct filmy’ has no member named ‘tytul’|
/home/kicex/Projekty/Struktura_1/main.cpp|30|error: ‘struct filmy’ has no member named ‘tytul’|
/home/kicex/Projekty/Struktura_1/main.cpp|36|error: ‘struct filmy’ has no member named ‘tytul’|
== Build finished: 7 errors, 0 warnings ===

Wersja CodeBlocks 10.5 (Ubuntu).

0

1.#include<string.h> wywal i daj #include <string>
2.std::string tytul;

0

dziękuję za szybką odpowiedz :)

0
#include <iostream>
#include <string>
struct filmy
{
    std::string tytul;
    int rok;
    int czas;
};

using namespace std;


int main()

{

     filmy dvd[5];
     dvd[1].tytul ="Ali G";
     dvd[1].rok = 1353;
     dvd[1].czas = 321;
     dvd[2].tytul = "Gwiezdne Jaja";
     dvd[2].rok = 1435;
     dvd[2].czas = 231;
     dvd[3].tytul = "Harry Potter";
     dvd[3].rok = 1342;
     dvd[3].czas = 123;
     dvd[4].tytul = "Gabriel";
     dvd[4].rok = 1432;
     dvd[4].czas = 124;
     dvd[5].tytul = "Stara Baśn";
     dvd[5].rok = 1543;
     dvd[5].czas = 154;

   int i;
  for(i=0; i<5; i++)
  {
  cout << "Płyta dvd nr. "[i] << " : \n";
  cout << "Tytuł : " << dvd[i].tytul << "\n";
  cout << "Rok Produkcji : " << dvd[i].rok << "r. \n";
  cout << "Czas trwania : " << dvd[i].czas << "min \n";
  }
  return(0);
} 

Teraz pojawił się niestety następny problem po uruchomieniu wiersza wyspiuje :

segmentation falut (core dumped)

0

Tablice indeksuje sie od zera.

0

Indeksy w tablicy są od 0 do ROZMIAR_TABLICY - 1. Wychodzisz poza zakres tablicy.

0

Już rozumiem problem rozwiązany program działa :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1