返回字符串 [英] returning strings
问题描述
我们如何从函数返回字符串或数组?我试过..
char [] some_func()//我认为char []会告诉编译器
返回是一个字符串
{
char str [100];
//某事物;
返回str;
}
提前感谢!
how do we return strings or arrays from a function? i tried..
char[] some_func() //where i thought char[] would tell the compiler
that the return is a string
{
char str[100];
//something;
return str;
}
thanks in advance!
推荐答案
MC felon写道:
MC felon wrote:
我们如何从函数返回字符串或数组?我试过..
char [] some_func()//我认为char []会告诉编译器
返回是一个字符串
{
char str [100];
//某事物;
返回str;
}
提前感谢!
how do we return strings or arrays from a function? i tried..
char[] some_func() //where i thought char[] would tell the compiler
that the return is a string
{
char str[100];
//something;
return str;
}
thanks in advance!
你在写C ++而不是C,这样做
std :: string some_func()
{
std :: string str;
//某事物;
返回str;
}
You''re writting C++ not C, do it like this
std::string some_func()
{
std::string str;
// something;
return str;
}
我在使用TC ++(一些旧版本)。请建议一些有效的东西
。
i work on TC++ (some old version). Please suggest something that works
in the same.
MC felon写道:
MC felon wrote:
我们如何从函数中返回字符串或数组?我试过..
char [] some_func()//我认为char []会告诉编译器
返回是一个字符串
{
char str [100];
//某事物;
返回str;
}
how do we return strings or arrays from a function? i tried..
char[] some_func() //where i thought char[] would tell the compiler
that the return is a string
{
char str[100];
//something;
return str;
}
因为当函数返回返回的
值时,它不会工作得太好已经死了。
您是否阅读过常见问题解答?
That won''t work too well since by the time the function returns the
value being returned is dead.
Did you read the FAQ?
这篇关于返回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!