【问题标题】:C++ strtok function during compile Eclipse says not declared in scope? [duplicate]编译Eclipse期间的C++ strtok函数说没有在范围内声明? [复制]
【发布时间】:2020-05-18 03:30:59
【问题描述】:

我正在练习一些 C++,但在拆分用户输入时遇到了麻烦。我正在使用带有 mingw32-gcc-g++-bin 9.2.0-1 的 eclipse ide 2020-03。下面是我的代码,

#include <iostream>
#include <string>
using namespace std;

int main() {
 string orderbook_symbol[500000][8]; //orderid, ordertime, symbol, buy/sell, qty, price, exp time, strike
 string user_order;
 char * pch;
 string done= "done trading";

 while(user_order.compare(done) != 0) {
     cin >> user_order;
     pch = strtok(user_order," ");
 }
}

当我点击编译时,我看到了这个错误:

23:22:06 **** Incremental Build of configuration Debug for project stasd ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\stasd.o" "..\\src\\stasd.cpp" 
..\src\stasd.cpp: In function 'int main()':
..\src\stasd.cpp:26:9: error: 'strtok' was not declared in this scope; did you mean 'strtol'?
   26 |   pch = strtok(user_order," ");
      |         ^~~~~~
      |         strtol
23:22:06 Build Failed. 1 errors, 0 warnings. (took 560ms)

我在这里举个例子:http://www.cplusplus.com/reference/cstring/strtok/ 而且我不明白为什么函数调用不在范围内错误。

【问题讨论】:

  • std::string != char*,这是您的问题。但是,我投票决定将其作为一个骗子关闭,因为该骗子解释了如何在仍然使用 std::string 的同时做你正在尝试的事情,我猜你想要。

标签: c++ strtok


【解决方案1】:

您包括&lt;string&gt;,而strtok&lt;string.h&gt;&lt;cstring&gt; 的一部分。

include string or string.h 了解这些之间的差异。

【讨论】:

    猜你喜欢
    • 2018-07-12
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-16
    • 2011-10-08
    • 2017-02-27
    相关资源
    最近更新 更多