Or how to make the function return std :: string?

    2 answers 2

    #include <iostream> std::string make_(void) { std::string x ("hello"); return x; } int main (void) { std::cout << make_(); return 0; } 
    • Thank. For some reason I do not compile. Apparently the hands are crooked. - Jakeroid
    • one
      How exactly is not compiled? This is C ++ code. - gecube
    • Already figured out. Thank. - Jakeroid
    • one
      And what was the problem? In the wrong file extension? :-) - gecube
     #include<stdio.h> #include<stdlib.h> char* f(int size) { char *s=(char*)malloc(sizeof(char)*size); return s; } int main() { char *a=f(10); free(a); return 0; } 

    Sorry, now changed under normal code =)

    • one
      The one who called the function will clean it. You do use the malloc function, although it also returns a pointer to dynamically allocated memory and does not clean it behind you. - AlexDenisov
    • Thanks for the "C" :). - Jakeroid