小编kaz*_*iam的帖子

HackerRank:第 1 天:C++ 中的数据类型

他们要我声明 3 个变量,一个是整数,一个是双精度,一个是字符串。然后从标准输入读取 3 行输入。我已经发布了我的解决方案,但它不起作用。我不知道为什么我的字符串变量没有从标准输入读取。当我在 VSCODE 中尝试时,它正在工作。你能告诉我我做错了什么吗?

这是问题所在

样本输入:

12
4.0    
is the best place to learn and practice coding!
Run Code Online (Sandbox Code Playgroud)

示例输出:

16
8.0
HackerRank is the best place to learn and practice coding!
Run Code Online (Sandbox Code Playgroud)

这是我用来检查我的 VSCODE 的代码。这有效!但它在 HackerRank 网站上不起作用。

#include <iostream>
#include <iomanip>
#include <limits>

using namespace std;

int main() {
    int i = 4;
    double d = 4.0;
    string s = "HackerRank ";


    // Declare second integer, double, and String variables.int x;
    int x;
    double y;
    string str;
    // …
Run Code Online (Sandbox Code Playgroud)

c++

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

抛出错误消息没有被 catch 方法捕获

我正在关注有关处理 YouTube 上获取错误的反应教程。我完全按照教员的做法做了,但由于某种原因,catch 方法没有捕获 throw 错误消息。这是代码:

const Home = () => {
  const [blogs, setBlogs] = useState(null);
  const [isPending, setIsPending] = useState(true);
  const [error, setError] = useState(null);

  useEffect(() => {
    setTimeout(() => {
      fetch("http://localhost:8000/blogs")
        .then((res) => {
          if (!res.ok) {
            throw Error("This error is not getting caught");
          }
          return res.json();
        })
        .then((data) => {
          setBlogs(data);
          setIsPending(false);
          setError(null);
        })
        .catch((err) => {
          setIsPending(false);
          setError(err.message);
        });
    }, 1000);
  }, []);

  return (
    <div className="home">
      {error && <div>{error} </div>}
      {isPending && <div>Loading...</div>}
      {blogs …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-hooks

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

标签 统计

c++ ×1

javascript ×1

react-hooks ×1

reactjs ×1