Skip to content

Instantly share code, notes, and snippets.

@Kedrigern
Last active October 1, 2015 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kedrigern/2047733 to your computer and use it in GitHub Desktop.
Save Kedrigern/2047733 to your computer and use it in GitHub Desktop.
C++: Loading file example.
// MSVS spouští program ve složce projektu, např:
// C:\Users\keddie\Documents\Visual Studio 2010\Projects\<name>
void print(char c) {
cout << c;
}
int _tmain()
{
ifstream in("in.txt", ifstream::in); // V MSVS se aplikace spousti v hlavni slozce aplikace
if( in ) {
cout << "otevren" << endl;
in.seekg(0, ios::end);
int n = (int) in.tellg();
in.seekg(0, ios::beg);
vector<char> v;
v.reserve(n);
while( ! in.eof() )
v.push_back( in.get() );
for_each(v.begin(), v.end(), print);
in.close();
}
else throw "No FILE";
cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment