
IDE 往往封装了 compile 和 link
std::
调用C++标准库时,要写上std::
仅仅使用非标准库文件iostream.h,则不用写
#include<iostream>using namespace std;int main(){cout<<"hello world";cout<<endl;return 0;}
#include <iostream>#include<fstream>#include<string>using namespace std;int main(){ofstream ofile("test.txt",ios::app);if(!ofile.fail()){cout<<"start write"<<endl;ofile<<"Mary";ofile<<"girl";ofile<<"20";}elsecout<<"can not open";return 0;}
#include <fstream>#include <vector>static std::vector<char> readFile(const std::string& filename) {std::ifstream file(filename, std::ios::ate | std::ios::binary);if (!file.is_open()) {throw std::runtime_error("failed to open file!");}}
