Last active
October 1, 2015 19:57
-
-
Save Kedrigern/2047733 to your computer and use it in GitHub Desktop.
C++: Loading file example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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