Skip to content

Instantly share code, notes, and snippets.

@son0p
Created February 20, 2016 18:37
Show Gist options
  • Save son0p/b0ef43bc81c1b641702f to your computer and use it in GitHub Desktop.
Save son0p/b0ef43bc81c1b641702f to your computer and use it in GitHub Desktop.

Revisions

  1. federico lopez created this gist Feb 20, 2016.
    41 changes: 41 additions & 0 deletions data_struct_example.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    ```C++
    // example about structures
    // from http://www.cplusplus.com/doc/tutorial/structures/
    #include <iostream>
    #include <string>
    #include <sstream>
    using namespace std;

    struct movies_t {
    string title;
    int year;
    } mine, yours;

    void printmovie (movies_t movie);

    int main ()
    {
    string mystr;

    mine.title = "2001 A Space Odyssey";
    mine.year = 1968;

    cout << "Enter title: ";
    getline (cin,yours.title);
    cout << "Enter year: ";
    getline (cin,mystr);
    stringstream(mystr) >> yours.year;

    cout << "My favorite movie is:\n ";
    printmovie (mine);
    cout << "And yours is:\n ";
    printmovie (yours);
    return 0;
    }

    void printmovie (movies_t movie)
    {
    cout << movie.title;
    cout << " (" << movie.year << ")\n";
    }
    ```