bool findTitlePrice函数代码帮助 [英] bool findTitlePrice function code help

查看:166
本文介绍了bool findTitlePrice函数代码帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下

展开 | 选择 | Wrap | 行号

解决方案

从allTitles数组中取出每条记录循环并将其与标题进行比较。使用strcmp进行比较。

如果它们相同,那么从第i个索引处的allPrices数组中获取值并返回值。


有些问题,你的函数是否返回价钱?那么为什么你已经将返回类型声明为布尔值?


问候

Dheeraj Joshi


不,它没有''这是一个寻找匹配然后返回bool类型所以我选择真假作为代表性条款


Dheeraj


怎么样我表示这是的,它是为了检查数组所有标题,然后在allprices数组中返回值说ith记录,以及它们存储相同数量的记录和匹配的数组,所以如果它说匹配的标题中的记录3输入字符串然后从allprice中的第3个元素中获取价格,如果它在标题返回值false上不匹配。


你能否正确执行此功能作为指南


我很乐意为你提供帮助。


由于你正在使用字符串对象作为标题,你必须是使用C ++。


因此你不应该使用rrays或strcmp。而不是数组,使用向量< string>。然后你可以使用字符串比较函数而不是strcmp。


strcmp仅适用于C字符串而不适用于C ++字符串。

展开 < span class =codeDivider> | 选择 | Wrap | Line编号

The Code is as Follows

Expand|Select|Wrap|Line Numbers

解决方案

Take each record from the allTitles array in for loop and compare it with the title. Use strcmp to do the comparison.
And if they are same then fetch the value from the allPrices array at the ith index and return the value.

Some questions, Does your function return the price? Then why you have declared the return type as boolean?

Regards
Dheeraj Joshi


No it doesn''t it is meant to be a find match then return bool type so i chose true and false as the representative terms

Dheeraj

how would i express this yes it is meant to check the array all titles then return the value say ith record in the allprices array as well as they store the same amount of records and are matched arrays so if it was say record 3 in titles that matches the input string then grab the price from the 3rd element in allprice if it doesn''t match on title return value false.

could you right up a function to do this as a guide as i haven''t used strcmp before

I am greatful for you help.


Since you are using string objects for titles, you must be using C++.

Because of that you should not be using either arrays or strcmp. Instead of the array, use a vector<string>. You can then use the string compare functions rather than strcmp.

strcmp only works for C strings and not C++ strings.

Expand|Select|Wrap|Line Numbers


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

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