#include <iostream> #include <string> #include <vector> #include <cstdio> #include <cstring> using namespace std; int main() { char str[128]; vector <char *> AllLine; while (1) { //输入带空格字符串方式一 /*string str1; getline(cin, str1);*/ //输入带空格字符串方式二 gets_s(str); char ch[] = ""; int size = sizeof(str); char *iStr = new char[size]; memcpy(iStr, str,size); AllLine.push_back(iStr); if (!strcmp(str, "</xmp>")) { break; } } int count = AllLine.size(); string productName; for (int i = 0; i < count; i++) { string iStr = AllLine[i]; if (strstr(iStr.c_str(),"h3")) { char *ch = const_cast<char *>(iStr.c_str()); char *p = strtok(ch, ">"); while (p) { string ik = p; if (strstr(p,"</")) { char *nameStr = strtok(p, "</"); while (nameStr) { string name = nameStr; productName = name; break; } //break; } p = strtok(NULL, ">"); } } if (strstr(iStr.c_str(), "In Stock")) { cout << productName << endl; } } system("pause"); } /* Main.cc: In function 'int main()': Main.cc:21:3: error: 'gets_s' was not declared in this scope gets_s(str); ^~~~~~ Main.cc:21:3: note: suggested alternative: 'gets' gets_s(str); ^~~~~~ gets Main.cc:22:8: warning: unused variable 'ch' [-Wunused-variable] char ch[] = ""; ^~ */ |
Double click to view unformatted code.