#include <iostream>
#include <cstring>
#include<stdarg.h>
usingnamespace std;
int main(void)
{
cout << "Please enter a character or integal" << endl;
string input;
getline(cin, input);
char str1[]="Hello";
if (strstr(str1, input))
{
printf(str1);
}
else
{
cout << "The character is not in the string1";
}
cout << "\n";
}
I figured out how to solve it...
The reason I want to use strstr function is because I need to search multiples (30 strings) using a string input(key in by user)
1 2 3 4 5
//just need to replace
getline(cin, input);
//with
char str90[31];
cin.get(str90, 31); // str90 is my cin, 31 is the no.of elements in the string(so it doesn't matter)//
#include <iostream>
#include <cstring>
#include<stdarg.h>
usingnamespace std;
int main(void)
{
cout << "Please enter a character or integal" << endl;
string input;
char str90[31];
cin.get(str90, 31);
char str1[]="Hello";
if (strstr(str1, str90))
{
printf(str1);
}
else
{
cout << "The character is not in the string1";
}
cout << "\n";
}
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
cout << "Please enter a character or integal: " ;
string input;
getline(cin, input);
string str1 = "Hello big fellow";
size_t location;
if((location = str1.find(input)) != std::string::npos)
{
cout << str1.substr(location) << '\n';
}
else
{
cout << "The character is not in the string1\n";
}
}
1 2
Please enter a character or integal: big
big fellow