我有一个文本文件,其中包含一系列两个字符串,每行以冒号分隔。
我使用 getline 来抓取整行,然后使用字符串流来拆分两个字符串并将它们放到一个向量上。该代码在第一遍时运行良好,它完美地抓取了字符串。然后在 while 循环的第二遍之后,依此类推,它不会获取新的输入。由于某种原因,字符串流似乎保留了原始的第一个值。
if (infile.is_open()) {
std::stringstream ss;
std::string current_line;
std::string tempProxy;
std::string tempPort;
while (std::getline(infile, current_line)) {
ss << current_line;
std::getline(ss, tempProxy, ':');
std::getline(ss, tempPort);
std::cout << tempProxy << " and " << tempPort << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
知道为什么它不想在第一次迭代之外的任何传递中从 current_line 中获取字符串吗?
我正在研究一些练习问题并且超级混淆如何返回"常量"
//Complete the following definition, so that "constant5" is a function that returns 5
// whenever it is invoked.
val constant5 : () => Int = {
}
//Complete the following definition, so that "constant" is a function that when
// invoked with integer n returns a function that returns n whenever it is invoked.
val constant : Int => () => Int = {
}
Run Code Online (Sandbox Code Playgroud)
以下是如何调用它们的示例
assert ({
val r1 : Int = constant5 ()
val r2 : Int …Run Code Online (Sandbox Code Playgroud)