[英]I get this error code in VS: 0x80070002 c++
When i try to run a code with the function "strtok" in it i get the error code 0x80070002.当我尝试运行带有“strtok”函数的代码时,我收到错误代码 0x80070002。 I included cstring, cctype, string.h and i also tried using /DEBUG FULL in Properties - Linker - Debugging, like a few other posts said but it still doesn't work.
我包括了 cstring、cctype、string.h,我还尝试在属性 - 链接器 - 调试中使用 /DEBUG FULL,就像其他一些帖子所说的那样,但它仍然不起作用。 Any clues why VS doesn't work with strtok?
为什么 VS 不能与 strtok 一起使用的任何线索? I also tried reinstalling VS and running a simple code like this:
我还尝试重新安装 VS 并运行如下简单代码:
#include <iostream>
#include <cstring>
#include <cctype>
#include <string.h>
using namespace std;
int main()
{
char s[100], * p;
cin.getline(s, 100);
p = strtok(s, " ");
cout << p;
return 0;
}
The desired behaviour would be to show me the first word of s.所需的行为是向我展示 s 的第一个单词。 Even when i try to run the code at https://en.cppreference.com/w/cpp/string/byte/strtok i get the same error.
即使我尝试在https://en.cppreference.com/w/cpp/string/byte/strtok上运行代码,我也会遇到同样的错误。
There are two methods to meet your needs;有两种方法可以满足您的需求;
Add _CRT_SECURE_NO_WARNINGS
in Properties->C/C++->Preprocessor->Preprocessor Definitions
.在
Properties->C/C++->Preprocessor->Preprocessor Definitions
添加_CRT_SECURE_NO_WARNINGS
。
Use strtok_s instead of strtok
:使用strtok_s而不是
strtok
:
int main() { char *buf; char s[100], *p; cin.getline(s, 100); p = strtok_s(s, " ", &buf); cout << p; return 0; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.