小编Ale*_*ijk的帖子

从文件 C++ 读取时无限循环

虽然我检查了while条件中的EOF,但 while 循环运行了无限次。但它仍然运行了无限次。下面是我的代码:

int code;
cin >> code;
std::ifstream fin;

fin.open("Computers.txt");

std::ofstream temp; // contents of path must be copied to a temp file then renamed back to the path file
temp.open("Computers.txt", ios_base::app);


string line;
string eraseLine = to_string(code);
while (  getline(fin, line) && !fin.eof() ) {
    if (line == eraseLine)
    {
        /*int i = 0;
        while (i < 10)
        {*/
            temp << "";
            //i++;
        //}
    }
    if (line != eraseLine) // write all lines to temp other …
Run Code Online (Sandbox Code Playgroud)

c++ getline infinite-loop file-handling

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

通过单击 javascript 中的 btn 更改正文背景颜色

我只想改变我的身体背景,比如在我点击 时切换btn,我想使用该addEventListener方法。我不确定为什么我的代码不起作用,它仅在 bodybackgroundcolor为紫色时才起作用。

这是我的代码:

var btn = document.querySelector("button");
var body = document.getElementByTagName("body")[0];

btn.addEventListener("click", function() {
  if(body.style.backgroundColor = "") {
    body.style.backgroundColor = "purple"
  } else {
    body.style.backgroundColor = ""}
  }
);
Run Code Online (Sandbox Code Playgroud)

javascript

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

位移行为

uint16_t a = 0x00 << 8 + 0xB9;
printf("%d",a);
Run Code Online (Sandbox Code Playgroud)

我期待185作为输出,但我得到0.

这里发生了什么?

c++ bit-shift

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

twig/wordpress 检查值是否在数组中

我正在测试我的树枝模板中的数组中是否存在一个值

<input type="hidden" name="s" value="{{ search_value }}">
  <label>
    <input type="checkbox"  
           name="cat[]" 
           value="3" 
           onchange="this.form.submit()"
           {% if 3 in cat  ? ' checked' : '' %} >
    <span>cbd</span>
  </label>
  {{ cat }}
Run Code Online (Sandbox Code Playgroud)

{{ cat }}在页面上的转储数组,我确定我的问题是一个愚蠢的语法错误。我得到的错误是

致命错误:未捕获的异常:模板意外结束。在....

如果我以这种方式包装,我会得到一个不同的错误

 {% (if 3 in cat)  ? ' checked' : '' %} >
Fatal error: Uncaught Exception: A block must start with a tag name.
Run Code Online (Sandbox Code Playgroud)

wordpress twig timber

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