测试超出范围
Test out of range
>我正在尝试测试访问字符串中的元素是否超出范围。我知道如何捕捉(std::out_of_range(,但我试图做的是如果(out_of_range(例:
string test;
int a;
test="123456789";
if(test.at(9)==out_of_range) //this isnt proper code but this is what im trying to accomplish
{
a=0;}
else
a=1;
我正在C++VS10编程
字符串的"范围"是它的大小。 如果其中有 1 个字符,则其 size(( 为 1。所以你可以做到
if(test.size(( <9(
你为什么不检查字符串的长度?
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 尝试通过多个向量访问变量时,向量下标超出范围
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 错误:未在此范围内声明'reverse'
- 正在将指针转换为范围
- 使用std::transform将一个范围的元素添加到另一个范围中
- 测试整数值范围的难度
- 测试完美哈希函数时超出范围错误
- 测试整数是否在范围内时,逻辑错误和不正确输出
- 使用谷歌测试期望一个给定范围内的值
- Google 测试 Gtest.cc:812:错误:未在此范围内声明'gettimeofday'
- 测试超出范围
- 用于测试对象是否与提升范围兼容的元函数
- 表达式:VS2015单元测试框架中向量测试的范围外错误
- STL函数,用于测试值是否在某个范围内
- 测试角度是否在范围内(有效且优雅)
- 测试检查该方法返回一个数字范围
- c++单元测试:改变成员范围
- 测试值是否在阈值范围内的最佳方法(性能方面)是什么