Jeg læser på STL for tiden så jeg lavede lige et eksempel:
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
if(argc != 2)
{
cout << "You must specify a filename and nothing else!" << endl;
return EXIT_FAILURE;
}
ifstream is(argv[1]);
while(!is.is_open())
{
cout << "Failed to open " << argv[1] << endl;
cout << "Hit enter to try again, q to quit" << endl;
char c;
cin.get(c);
if(c == 'q')
return EXIT_FAILURE;
is.open(argv[1]);
}
vector<string> input;
string st;
while(getline(is, st))
input.push_back(st);
sort(input.begin(), input.end());
copy(input.begin(), input.end(), ostream_iterator<string>(cout, "\\n"));
return EXIT_SUCCESS;
}
Jeg har ingen idé om hvordan man putter ting i en db.