簡體   English   中英

我在哪里可以找到提供 String.substring() 方法的庫?

[英]Where can I find the library that provides String.substring() method?

我正在嘗試在 Linux 上編譯 Arduino 項目,抽象出硬件部分。 考慮以下行:

int keyNumRepeat = userInputPrev.substring(6, 8).toInt();

看起來 Arduino 使用了一些非標准庫,這不在我的系統上:

hsldz_totp_lock/hsldz_totp_lock.ino:335:38: error: ‘String’ {aka ‘class std::__cxx11::basic_string<char>’} has no member named ‘substring’; did you mean ‘substr’?
  335 |     int keyNumRepeat = userInputPrev.substring(6, 8).toInt();
      |                                      ^~~~~~~~~
      |                                      substr
make: *** [Makefile:54: sim] Error 1

它是否在某個地方可用,以便我可以在嘗試編譯時將其包含在我的項目中? 或者它是否嚴重依賴於其他 Arduino 實現細節?

看起來 Arduino 具有String的自定義實現。

由於它是開源的,這里是headerclass文件。 我只瀏覽了它們,但它們似乎並不嚴重依賴Arduino 核心 API 的 rest

也就是說,您最好用標准c++替換它們的實現。 特別是如果它們只是生活質量的改善。 使用string::substrstd::stoi的等效代碼應該是:

int keyNumRepeat = std::stoi(userInputPrev.substr(6, 8));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM