"at"运算符在C++做什么?例如,string.at 或 word.at
What does the "at" operator do in C++? For example, string.at or word.at
// Iterate(loop/repetition) over the word
for(int i = 0; i < (int)word.size(); i++ ){
// Get a character
char ch = word.at(i);
// If the character matches the character we're looking for
if(searchCh == ch){
// Increment a counter
counter++; // counter = counter + 1
word.at(i)在操作符中是什么意思,或者"at"操作符在c++中是做什么的?例如:string。At或word.at
你的意思可能是" word.at(i)
和word[i]
有什么不同"?
word.at(i)
一般检查i
是否在范围内,如果不在则抛出异常。如果i
不在范围内,word[i]
就是未定义行为。
同样,对于word[word.size()]
,您可以访问隐式尾随的' '
-字节,但对于word.at(word.size())
,索引超出了范围。
at()
是c++中的成员函数。s.at()
返回字符串中i
位置的字母。但是如果这个位置是如果不在范围内,则抛出异常
相关文章:
- cppcheck在const std::string[]上引发警告
- 将std::string传递给WriteConsole API
- 为std::string的某个索引赋值
- std中有类似find_last_of的函数,而string中没有
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 使用 std::string () const 函数启动线程或未来
- 使用char类型将decimal转换为string,将string转换为decimal
- std::string [] 运算符和 at() 之间的区别
- string.at if 语句不返回任何内容
- Segfault at string::assign
- c at()函数class string访问紫色的函数
- 使用string.at()在字符串c++中查找一个空格
- 如何使用 string.at 为其赋值
- String.at() 返回时髦的数字
- C++ " I want to add a new string at the end of the file How Can I do it? please help"中的文件处理
- 使用 string.at() 或字符串 []
- 识别字符串中的 C 11 关键字 (string.at() 问题)
- String.at() 不与字符进行比较
- string.at()导致Std::out_of_range错误
- "at"运算符在C++做什么?例如,string.at 或 word.at