初学C++(三)

发布时间:2026/7/30 2:56:39
初学C++(三) // ConsoleApplication2.cpp : 此文件包含 main 函数。程序执行将在此处开始并结束。 //025转换和替换 #include iostream #include string using namespace std; //字符串和数字的转换 //字符串转化为数字 int main() { std::cout Hello World!\n; auto il stoi(1234); cout il il endl; cout stod(123.5) endl; cout stof(123.6f) endl; cout stoll(123123123) endl; //数字转化字符 auto pi to_string(3.1412); cout pi pi endl; cout to_string(1024) endl; //字符串拼接 string log; string txt login system; string user xcj; int threadid 1023; log user : txt : to_string(threadid); cout log endl; log [debug] log; log ;; cout log endl; //7查找和替换 string strfind test for find [user] login system; auto pos strfind.find([test]);//查找成功返回位置 if (pos string::npos) { cout [test] not find! endl; } string key{ [user] }; pos strfind.find(key); if (pos ! string::npos) { cout find key : pos endl; cout strfind.substr(pos) endl; cout strfind.substr(pos key.size()) endl; } //替换 auto rep strfind.replace(pos, key.size(), root); cout rep: rep endl; cin.get(); return 0; } // 运行程序: Ctrl F5 或调试 “开始执行(不调试)”菜单 // 调试程序: F5 或调试 “开始调试”菜单 // 入门使用技巧: // 1. 使用解决方案资源管理器窗口添加/管理文件 // 2. 使用团队资源管理器窗口连接到源代码管理 // 3. 使用输出窗口查看生成输出和其他消息 // 4. 使用错误列表窗口查看错误 // 5. 转到“项目”“添加新项”以创建新的代码文件或转到“项目”“添加现有项”以将现有代码文件添加到项目 // 6. 将来若要再次打开此项目请转到“文件”“打开”“项目”并选择 .sln 文件这个是C里的转换和替换