#include <iostream>
#include <cstring>
using namespace std;
auto print = [] (auto const& v) {
cout << "Print using Lambda" << endl;
for (const auto& e:v) { cout << e;}
cout << endl;
};
/* User defined function to check
the string length using size() */
bool checkEmptyStringS(const string &s)
{
return s.size() == 0;
}
/* User defined function to check
the string length using length() */
bool checkEmptyStringS1(const string &s)
{
return s.length() == 0;
}
/* User defined function to check
the string length using strlen */
bool checkEmptyStringS2(const string &s)
{
return strlen(s.data()) == 0;
}
int main()
{
//String declaration
string s;
//String Initialisation
string s1 = "abc";
string s2{"def"};
// Check if the string is empty using built-in function
if (s.empty()) {
cout << "\nString s is empty." << endl;
}
cout << "Enter the user name: ";
// Reading from the user
cin >> s;
// Check if the string is empty using user defined function
checkEmptyStringS(s) ?
cout << "\nString s is still empty." << endl :
cout << "\nString s is not empty, now." << endl;
checkEmptyStringS1(s1) ?
cout << "\nString s1 is empty." << endl :
cout << "\nString s1 is not empty." << endl;
checkEmptyStringS2(s2) ?
cout << "\nString s2 is empty." << endl :
cout << "\nString s2 is not empty." << endl;
// Printing the string
cout<< "\nEntered string " << s << endl;
cout << "s1 " << s1 << " s2 " << s2 << endl;
// Print using lambda
print(s);
return 0;
}