c++ - 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. 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. Any clues why VS doesn't work with strtok? I also tried reinstalling VS and running a simple code like this:
#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. Even when i try to run the code at https://en.cppreference.com/w/cpp/string/byte/strtok i get the same error.
解决方案
There are two methods to meet your needs;
Add
_CRT_SECURE_NO_WARNINGS
inProperties->C/C++->Preprocessor->Preprocessor Definitions
.Use strtok_s instead of
strtok
:int main() { char *buf; char s[100], *p; cin.getline(s, 100); p = strtok_s(s, " ", &buf); cout << p; return 0; }
推荐阅读
- c# - 在 Windows Ce C# 中将字符串转换为 XElement
- flutter - Flutter - 堆栈中定位小部件的效率
- java - Java进程在没有记录的情况下被杀死
- php - 媒体中可下载文件类型的扩展。Drupal 8
- ios - 使用UIButtons在自定义键盘中输入UITextFields,键盘重新出现,不输入文本
- azure - Azure - Advanced Application restart - access to instance before it's ready
- angular - Is it safe to use ngx permissions in angular for acl management?
- html - Stretching ::before element to width of screen
- c# - 将字符串 JSON 转换为 Camel Case
- javascript - AngularJS/JQuery 未知异常:访问被拒绝