Compiled the code on g++ and it won't work, why?

Code:
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;

void func(string t) {
    cout << t << endl;
}

int main() {
    list < string > prod_code;
    string temp;
    do {
 cout << "Enter Product Code: ";
 if (cin >> temp) {
     prod_code.push_back(temp);
 } else {
     break;
 }
    } while (1);

    sort( prod_code.begin(), prod_code.end() );
    for_each(prod_code.begin(), prod_code.end() , func);
    return 0;
}