函数返回字符串数组 [英] function to return string array

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

问题描述

我创建了一个函数,你发送一个字符串,并根据空格进行标记,所以我给它发一个字符串给它返回一个字符串数组,但是在函数的声明中它表示


错误C2470:''splitter'':看起来像一个函数定义,但是没有参数列表;跳过明显的身体



错误C2092:''splitter''数组元素类型无法正常运行


我的标题是


字符串拆分器[](字符串行)


i前几天读取的返回值可以是任何长度,只要它的一个对象, int,string,array,只要它是一个对象,那么我做错了什么?


提前感谢

解决方案

< blockquote>


i创建了一个函数,你发送一个字符串,并根据空格进行标记,所以我给它发一个字符串给它返回一个字符串数组,但是在声明中它说的功能


错误C2470:''splitter'':看起来像一个函数定义,但是没有参数列表;跳过明显的身体



错误C2092:''splitter''数组元素类型无法正常运行


我的标题是


字符串拆分器[](字符串行)


i前几天读取的返回值可以是任何长度,只要它的一个对象, int,string,array,只要它是一个对象,那么我做错了什么?


提前感谢



,因为spliter [],你不能将数组元素类型作为返回值。将其更改为* spliter并且它将起作用。


Savage

<非常感谢

非常感谢:D它工作了


一切正常,功能明智,但是当我打电话给它时,我收到了这个错误


警告C4172:返回本地变量的地址或临时的


你真高兴知道为什么会这样吗?非常感谢


我想我必须用公共功能宣布它,我做了,但现在我得到一个新的错误,


1> retrieveGeoCmdCmd.obj:错误LNK2019:未解析的外部符号" class std :: basic_string< char,struct std :: char_traits< char>,class std :: allocator< char> > __cdecl splitter(类std :: basic_string< char,struct std :: char_traits< char>,class std :: allocator< char>>)" (?分离器@@ YA?AV?

i created a function which u send a string, and it tokenizes according to spaces, so i send it a string for it to return me a string array, but on the declaration of the function it says

error C2470: ''splitter'' : looks like a function definition, but there is no parameter list; skipping apparent body
and
error C2092: ''splitter'' array element type cannot be function

and my header is

string splitter[](string line)

i read the other day that the return value could be anythin as long as its one object ,int, string, array, as long as its one object, so what am i doing wrong?

thanks in advance

解决方案

i created a function which u send a string, and it tokenizes according to spaces, so i send it a string for it to return me a string array, but on the declaration of the function it says

error C2470: ''splitter'' : looks like a function definition, but there is no parameter list; skipping apparent body
and
error C2092: ''splitter'' array element type cannot be function

and my header is

string splitter[](string line)

i read the other day that the return value could be anythin as long as its one object ,int, string, array, as long as its one object, so what am i doing wrong?

thanks in advance

it''s because of spliter[],you cannot have array element type as a return value.Change it to *spliter and it will work.

Savage


thanks a lot :D it worked

it all worked, function wise, but when i call it, i get this error

warning C4172: returning address of local variable or temporary

do u happpen to know why that is?? thanks a lot again


well i figured i had to have it declared withthe public functions, which i did, but now i get a new error,

1>retrieveGeoCmdCmd.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl splitter(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?splitter@@YA?AV?


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

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