Created
March 11, 2016 14:52
-
-
Save blippy/c469714259da25317d84 to your computer and use it in GitHub Desktop.
Example of reading in a file in C++
This file contains hidden or 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
| #include "mcstats.h" | |
| #include <assert.h> | |
| #include <stdlib.h> | |
| //#include <stdio> | |
| #include <iostream> | |
| #include <fstream> | |
| #include <string> | |
| using std::cout; | |
| using std::endl; | |
| int main() | |
| { | |
| std::ifstream ifs; | |
| ifs.open("../maff/xlsm/sort.txt"); | |
| std::string str; | |
| std::getline(ifs, str); | |
| cout << str << endl; | |
| int n = stoi(str); | |
| std::vector<double> ds; | |
| assert(n>0); | |
| for(int i=0; i<n; i++){ | |
| std::getline(ifs, str); | |
| double d = stod(str); | |
| ds.push_back(d); | |
| } | |
| ifs.close(); | |
| sortd(ds); | |
| for(int i=0; i<n; i++){ | |
| cout << ds[i] << endl; | |
| } | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment