(´>∀)人(´・ω・)ノヽ(・ε・*)人(-д-`)
Ruby @Sprout 2022
(´>∀)人(´・ω・)ノ日主ヽ(・ε・*)人(-д-`)
Ruby @Sprout 2022
(´>∀)人(´・ω・)ノ今日主題ヽ(・ε・*)人(-д-`)
Ruby @Sprout 2022
人(´・ω・)ノ 今日主題 ヽ(・ε・*)人
Ruby @Sprout 2022
ω・)ノ 今日主題 ヽ(・ε
Ruby @Sprout 2022
)ノ 今日主題 ヽ(
Ruby @Sprout 2022
今日主題
Ruby @Sprout 2022
C++ String & FileIO
Ruby @Sprout 2022
C-string Review
std::string
Applications of std::string
std::stringstream
FileIO
Applications of FileIO
C-string Review
std::string
Applications of std::string
std::stringstream
FileIO
Applications of FileIO
是 Stack 嗎?還是 Heap 呢?答案是:都不是!
C-string Review
std::string
Applications of std::string
std::stringstream
FileIO
Applications of FileIO
Any questions?
C-string Review
std::string
Applications of std::string
std::stringstream
FileIO
Applications of FileIO
Solution
哈哈不給你看,上課講解!
Any questions?
C-string Review
std::string
Applications of std::string
std::stringstream
FileIO
Applications of FileIO
ostream
cout
cerr
clog
istream
cin
C-string Review
std::string
Applications of std::string
std::stringstream
FileIO
Applications of FileIO
Create (Overwrite) a file
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream outFile;
outFile.open("out.txt");
outFile << "Some text";
outFile.close();
return 0;
}
Load an existing file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inFile;
inFile.open("in.txt");
string s;
while (inFile >> s) cout << s << endl;
inFile.close();
return 0;
}
Load and overwrite an existing file
#include <bits/stdc++.h>
using namespace std;
const string FILENAME = "last_login_time.txt";
int main() {
ifstream inFile; ofstream outFile;
inFile.open(FILENAME);
time_t curr = time(nullptr), last; inFile >> last;
inFile.close();
cout << "It has been " << curr-last << " seconds since your last login." << endl;
outFile.open(FILENAME);
outFile << curr;
outFile.close();
return 0;
}
C-string Review
std::string
Applications of std::string
std::stringstream
FileIO
Applications of FileIO
Loading testcases
#include <bits/stdc++.h>
using namespace std;
int main() {
ifstream inFile("testcase.txt");
int n, _max = -1;
while (inFile >> n)
_max = max(n, _max);
cout << "The max numbers out of all numbers in the testcase: " << _max << endl;
inFile.close();
return 0;
}
感謝參與!