如何在C++中找到单词的长度? [英] How to find the lenght of the word in C++?
本文介绍了如何在C++中找到单词的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有一些词,我们应该确定其长度.我怎样才能做到这一点?示例输入:你好"- 没有引号;示例输出:5
We have some word, that we should identify the length of. How can I do that? Example INPUT: "hello" - without quotes; Example OUTPUT: 5
推荐答案
如果输入包含在 std::string 中,您可以找到 Ravi 所述的长度.如果它是一个 C 字符串,你可以用
If input is contained in a std::string you can find the length as stated by Ravi. If it's a C string you find the length with
int len = strlen(INPUT);
在 C/C++ 中,大写通常用于常量,因此最好将字符串命名为 input,而不是 INPUT.
In C/C++ upper case is normally used for constants so it's better to name the string input, not INPUT.
这篇关于如何在C++中找到单词的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文