小编moc*_*de9的帖子

C++ Stringstream 只拾取第一个字符串

我有一个文本文件,其中包含一系列两个字符串,每行以冒号分隔。

我使用 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 中获取字符串吗?

c++ string stream

4
推荐指数
1
解决办法
1928
查看次数

Scala如何返回常量

我正在研究一些练习问题并且超级混淆如何返回"常量"

//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)

scala constants function

0
推荐指数
1
解决办法
460
查看次数

标签 统计

c++ ×1

constants ×1

function ×1

scala ×1

stream ×1

string ×1