View Code of Problem 98

#include <iostream>
#include <string>
#include <vector>
#include <cstdio>

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:20:3: error: 'gets_s' was not declared in this scope
   gets_s(str);
   ^~~~~~
Main.cc:20:3: note: suggested alternative: 'gets'
   gets_s(str);
   ^~~~~~
   gets
Main.cc:24:3: error: 'memcpy' was not declared in this scope
   memcpy(iStr, str,size);
   ^~~~~~
Main.cc:24:3: note: 'memcpy' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
Main.cc:5:1:
+#include <cstring>
 
Main.cc:24:3:
   memcpy(iStr, str,size);
   ^~~~~~
Main.cc:26:8: error: 'strcmp' was not declared in this scope
   if (!strcmp(str, "</xmp>"))
        ^~~~~~
Main.cc:26:8: note: 'strcmp' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
Main.cc:21:8: warning: unused variable 'ch' [-Wunused-variable]
   char ch[] = "";
        ^~
Main.cc:40:7: error: 'strstr' was not declared in this scope
   if (strstr(iStr.c_str(),"h3"))
       ^~~~~~
Main.cc:40:7: note: 'strstr' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
Main.cc:43:14: error: 'strtok' was not declared in this scope
    char *p = strtok(ch, ">");
              ^~~~~~
Main.cc:43:14: note: suggested alternative: 'strtoq'
    char *p = strtok(ch, ">");
              ^~~~~~
              strtoq
Main.cc:62:7: error: 'strstr' was not declared in this scope
   if (strstr(iStr.c_str(), "In Stock"))
       ^~~~~~
Main.cc:62:7: note: 'strstr' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
*/

Double click to view unformatted code.


Back to problem 98