我可以在while循环中放置原型和定义吗? [英] Can I put a prototype and definition in a while loop?
本文介绍了我可以在while循环中放置原型和定义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在命令提示符下为c ++制作一个电影列表。然后,用户需要键入一组字母,然后计算机在电影列表中找到这些字母,并打印出该组字母被提及的次数。
我尝试过:
这是我的导师给我们的代码
I have to make a list of movies in the command prompt for c++. Then the user needs to type in a group of letters that then the computer finds in the list of movies, and prints out the number of times that group of letters is mentioned.
What I have tried:
this is the code my instructor gave us
cout << "Words beginning with 'ca': " << endl;
for (int i = 0; i < words.size(); i++)
{
if (words[i].substr(0, 2) == "ca")
/// OR: words[i].find("ca") == 0
{
cout << words[i] << endl;
}
total += words[i].length();
}
推荐答案
不,你不应该。常量应该是全局的,并且位于源文件的顶部,并且带有一些命令,大写字母用于良好的编码实践。在重用质量中始终写入代码。
No you shouldnt. Constant should be global and at the top of a source file and with some commands, upper letters for good coding practice. Write always code in "reuse quality".
// Prefix is recommanded
const char *PREFIX_MOVIE = "ca";
这篇关于我可以在while循环中放置原型和定义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文