Sunday, February 25, 2018

C++ Program to cast a class A object to a char * object.

#include <iostream>
#include <cstring>
using namespace std;
class A {
public: char *str;
    A(char *s) : str(s) { }

operator char*() {return str;}


};
int main() {
    char input[20];
    cin >> input;
    A a(input);
    // A ==> char *
    char *s = static_cast<char*>(a);
    strcat(s, "-success");
    cout << s;
    return 0;
}

Thanks
Happy Programming !

No comments:

Post a Comment

Query for finding high dividend paying stocks

 Post the following query in Screen.in, to get list of high dividend yield stocks: Dividend yield > 6 AND Dividend last year > 1000 AN...