简体   繁体   中英

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;

  1. Add _CRT_SECURE_NO_WARNINGS in Properties->C/C++->Preprocessor->Preprocessor Definitions .

  2. 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; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM