2023.5.8
1 #include <iostream> 2 using namespace std; 3 #include <fstream> 4 #include <iomanip> 5 void test() 6 { 7 int num; 8 cout << "请输入一个十进制整数:" << endl; 9 cin >> num; 10 //十进制输出 11 cout << "十进制输出为:" << num << endl; 12 //八进制输出 13 cout << "八进制输出为:"<<oct << num << endl; 14 //十六进制输出 15 cout << "十六进制输出为:" << hex << num << endl; 16 } 17 int main() 18 { 19 test(); 20 return 0; 21 }
1 //11-9 2 #include <iostream> 3 using namespace std; 4 #include <fstream> 5 #include <iomanip> 6 #include <string> 7 void test() 8 { 9 ofstream ofs; 10 ofs.open("test1.txt", ios::out); 11 ofs << "我说我不再拥有" << endl; 12 ofs << "你说你还爱我" << endl; 13 ofs << "我说我说我开不了口" << endl; 14 ofs.close(); 15 } 16 void test01() 17 { 18 string buf; 19 int counter = 0; 20 ifstream ifs("test1.txt",ios::in); 21 ofstream ofs("test2.txt",ios::out); 22 if (!ifs.is_open()) 23 { 24 cout << "文件打开失败" << endl; 25 return; 26 } 27 while (getline(ifs, buf)) 28 { 29 ofs << ++counter << "." << buf << endl; 30 } 31 ifs.close(); 32 ofs.close(); 33 } 34 int main() 35 { 36 test(); 37 test01(); 38 return 0; 39 }
1 //11-10 2 #include <iostream> 3 using namespace std; 4 #include <fstream> 5 #include <iomanip> 6 #include <string> 7 void test() 8 { 9 int num = 0; 10 char c; 11 char a ='我'; 12 ifstream ifs; 13 ifs.open("test1.txt", ios::in); 14 if (!ifs.is_open()) 15 { 16 cout << "文件打开失败" << endl; 17 } 18 19 while ((c = ifs.get()) != EOF) 20 { 21 22 if (a == c) 23 { 24 num++; 25 } 26 } 27 ofstream ofs; 28 ofs.open("test2.txt", ios::out); 29 ofs <<"‘我’的个数为:" << num << endl; 30 ofs.close(); 31 ifs.close(); 32 } 33 int main() 34 { 35 test(); 36 return 0; 37 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?