函数返回字符串 [英] Function return string

查看:107
本文介绍了函数返回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么函数不能返回字符串? (错误:新类型可能不是

在返回类型中定义)...

我该如何解决?

我想到的将字符串传递给函数,但这将使我重新设计大部分应用程序并且我想避免它..是否有任何其他

方法来克服这个问题?


tia,streamkid

Why can''t a function not return string? (error: new types may not be
defined in a return type)...
How can i solve it?
I thought of passing the string into the function, but that will make
me redesign most of the app and i want to avoid it.. is there any other
way to overcome this?

tia, streamkid

推荐答案

st ******* @ gmail.com napsal:
st*******@gmail.com napsal:

为什么不能函数不返回字符串? (错误:新类型可能不是

在返回类型中定义)...

我该如何解决?

我想到的将字符串传递给函数,但这将使我重新设计大部分应用程序并且我想避免它..是否有任何其他

方法来克服这个问题?


tia,streamkid
Why can''t a function not return string? (error: new types may not be
defined in a return type)...
How can i solve it?
I thought of passing the string into the function, but that will make
me redesign most of the app and i want to avoid it.. is there any other
way to overcome this?

tia, streamkid



你这里写的没有代码,所以很难想到,你的

问题。但肯定有可能返回字符串:


#include< string>

std :: string RetString()

{

返回" Hello" ;;

}


如果你的意思是返回C字符串,它也适用:

const char * RetCString()

{

return" Hello" ;;

}

You wrote here no code, so it is very hard to think, where is your
problem. But there is definitely possible to return strings:

#include <string>
std::string RetString()
{
return "Hello";
}

If you mean returning C-strings, it works too:
const char* RetCString()
{
return "Hello";
}



st*******@gmail.com 写道:

为什么函数不能返回字符串? (错误:新类型可能不是

在返回类型中定义)...

我该如何解决?

我想到的将字符串传递给函数,但这将使我重新设计大部分应用程序并且我想避免它..是否有任何其他

方法来克服这个问题?


tia,streamkid
Why can''t a function not return string? (error: new types may not be
defined in a return type)...
How can i solve it?
I thought of passing the string into the function, but that will make
me redesign most of the app and i want to avoid it.. is there any other
way to overcome this?

tia, streamkid



请粘贴一段代码。没有什么可以阻止你返回一个类或一个C风格的字符串来获得



另外,请发布你正在编译它的编译器和操作系统。


Please paste a snippet of your code. There is nothing stopping you
from returning a class or a C style string.

Also, please post what compiler and OS you are compiling this on.




?/? Ondra Holub Y ??á??:

?/? Ondra Holub Y??á??:
st ******* @ gmail.com napsal:
st*******@gmail.com napsal:

为什么函数不能返回字符串? (错误:新类型可能不是

在返回类型中定义)...

我该如何解决?

我想到的将字符串传递给函数,但这将使我重新设计大部分应用程序并且我想避免它..是否有任何其他

方法来克服这个问题?


tia,streamkid
Why can''t a function not return string? (error: new types may not be
defined in a return type)...
How can i solve it?
I thought of passing the string into the function, but that will make
me redesign most of the app and i want to avoid it.. is there any other
way to overcome this?

tia, streamkid



你在这里写的没有代码,所以很难想到,你的

问题。但肯定有可能返回字符串:


#include< string>

std :: string RetString()

{

返回" Hello" ;;

}


如果你的意思是返回C字符串,它也适用:

const char * RetCString()

{

return" Hello" ;;

}


You wrote here no code, so it is very hard to think, where is your
problem. But there is definitely possible to return strings:

#include <string>
std::string RetString()
{
return "Hello";
}

If you mean returning C-strings, it works too:
const char* RetCString()
{
return "Hello";
}



感谢快速回答:)


我试过这个并且它有效:s

但是

i有

class a

{

public:

string getit();

私有:

字符串astring;

}


i尝试编译它并说出错误提到以上......


thanks for the quick answer :)

well i tried this and it works :s
BUT
i have
class a
{
public:
string getit();
private:
string astring;
}

i try to compile it and is says the error mentioned above...


这篇关于函数返回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆