how to get string from other function?
i tried this , but come error...
i using Visual Basic C++....

void main()
{
   char name[51];
   name=NAME();
}

int NAME()
{
   char names[51];
   names="john";
}

C++ has two kinds of strings. The strings inherited from C are char arrays with a terminating '\0' character. All of the rules for arrays apply, which means you can only return a pointer to the array somehow. But if the array is local to the function returning it, you are returning a bogus pointer. Not a good thing. ;)

The strings defined by C++ are class objects of the std::string type. They have copy semantics, so it is much easier to use them than the C type strings. I recommend that you use C++ strings until you start getting into the lower levels of C++ because C type strings are very easy to get wrong:

#include <iostream>
#include <string>

std::string Name()
{
    return "Tom";
}

int main()
{
    std::string name = Name();

    std::cout << "My name is " << name << '\n';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.