8.1#
8.2#
Copy
#include <iostream>
using namespace std;
istream &readeof(istream &in)
{
string s;
while (in >> s && !in.eof())
{
cout << s;
in.clear();
}
in.clear();
}
int main(int argc, char const *argv[])
{
readeof(cin);
cout << "Get EOF" << endl;
while (1)
;
return 0;
}
8.3#
Copy
while (cin >> i)
8.4#
8.5#
Copy
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
void Each(istream &in, string option)
{
if (!in)
{
cerr << "Check FIle" << endl;
while (1)
;
}
string s;
vector<string> v;
if (option == "line")
{
while (getline(in, s))
v.push_back(s);
}
else
{
while (in >> s)
v.push_back(s);
}
for (auto a : v)
{
cout << a << endl;
}
}
int main(int argc, char const *argv[])
{
string filepath = "C:\\JLink.log";
ifstream in(filepath);
cout << "Split By Line" << endl;
Each(in, "line");
in.close();
cout << "Split By Word" << endl;
in.open(filepath);
Each(in, "word");
while (1)
;
return 0;
}
8.9#
Copy
#include <iostream>
#include <sstream>
using namespace std;
istream &readeof(istream &in)
{
string s;
while (in >> s)
{
cout << s;
in.clear();
}
cout << endl;
in.clear();
}
int main(int argc, char const *argv[])
{
stringstream ss("1234567");
readeof(ss);
cout << "Get EOF" << endl;
while (1)
;
return 0;
}
8.10#
Copy
#include <sstream>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char const *argv[])
{
string filepath = "C:\\JLink.log";
ifstream in(filepath);
if (!in)
{
cout << "Check File" << endl;
}
vector<string> line;
string s;
while (getline(in, s))
{
line.push_back(s);
}
for (auto c : line)
{
stringstream ss(c);
string ch;
while (ss >> ch)
{
cout << ch << endl;
}
}
while (1)
;
return 0;
}
8.11#
Copy
8.12#
Copy
我们为什么没有在PersonInfo中使用类内初始化?
因为这里我们使用了聚合类,不需要类内初始化
8.14#
Copy
我们为什么要将entry和nums定义为const auto&。
使用引用避免拷贝
使用const 因为不会赋值
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?