如何在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.