刚刚练习华为机试上的题目遇到了这个问题,奉上两个小题:

//题目描述
//
//描述:
//输入一个整数,将这个整数以字符串的形式逆序输出
//程序不考虑负数的情况,若数字含有0,则逆序形式也含有0,如输入为100,则输出为001
//
//
//输入描述 :
//输入一个int整数
//
//
//输出描述 :
//将这个整数以字符串的形式逆序输出 //
////先居然想到了用栈,因为像数制转换一样,要逆序输出,结果直接从后面取每一位输出即可。
#include<iostream>
using namespace std;
int main()
{
int input;
while (cin>>input)
{
int bit;
while (input)
{
bit = input % ;
cout << bit;
input /= ;
}
cout << endl;
}
return ;
} //题目描述
//
//写出一个程序,接受一个字符串,然后输出该字符串反转后的字符串。例如:
//
//输入描述 :
//输入N个字符
//
//
//输出描述 :
//输出该字符串反转后的字符串 #include<iostream>
#include<string>
using namespace std;
int main()
{
string str="";
while (getline(cin,str))
{
////string subscript out of range
////1.有说没有初始化的,2有说cin >> n; 后面加一句cin.ignore(); 过滤掉上一句cin中的回车 ;但是没有找到答案
//// for (int /*size_t*/ i = str.size()-1; i >=0; i--)    //发现问题,size_t为unsigned int,i=-1时,补码为正数,数组溢出 //改为int即可
//for (size_t i = str.size()-1; i >=0; i--)
//{
// cout << str[i]; //为什么这样做就会数组大小溢出
//}
for (size_t i = str.size(); i >; i--) //正确
{
cout << str[i-];
}
cout << endl;
}
return ;
}

string subscript out of range的更多相关文章

  1. java.lang.StringIndexOutOfBoundsException: String index out of range: 0

    hibernet 报错 java.lang.StringIndexOutOfBoundsException: String index out of range: 0 处理方法  数据表字段为char ...

  2. unordered_map 遇到 vector subscript out of range 的错误提示

    错误类型 当调用unordered_map的函数的时候,会出现如下问题: 使用linux运行则会提示 float exeption(core dump) 原因 遇到vector subscript o ...

  3. Spring Boot 启动报错 Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 37

    使用命令 java -jar springBoot.jar  启动项目,结果报错如下: Exception at java.lang.String.substring(String.java:) at ...

  4. IndexError:string index out of range

    IndexError:string index out of range 出现在下标越界的情况,如 item[1],可能为空的时候下标就会越界

  5. hibernate createSQLQuery StringIndexOutOfBoundsException: String index out of range: 0

    有一个sql用union拼接的如下: select id,(**还有很多字段**),'' as NewName from tb1 union select id,(**还有很多字段**),name a ...

  6. mac安装MySQLdb:IndexError: string index out of range

    使用mac安装MySQLdb的时候出现string index out of range 大概的错误是这样的: 然后尝试手动安装,我下载了包后,依然出现这个错误. 于是百度了下: https://ww ...

  7. tk.mybatis 报错:tk.mybatis.mapper.MapperException: tk.mybatis.mapper.MapperException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apiLogMapper ...

  8. vector subscript out of range

    报这个错时会弹出一个窗口,貌似内存溢出,这是什么由于vector存放的数据超出了vector的大小所造成的. 解决方法如下: 在Vector<string> vector之后,不能直接通过 ...

  9. tcl之string操作-length/index/range/replace

随机推荐

  1. Backbone seajs demo2

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Web Server tomcat配置网站

    tomcat配置网站 环境变量: 变量名:CATALINA_HOME 变量值:安装路径 1.在tomcat文件夹的conf"catalina"localhost(对于Tomcat6 ...

  3. 了解ThinkPHP(一)

    1.项目开发,中,会遇到的问题: 1). 多人开发项目,分工不合理,(html   php   mysql) 2). 代码风格不一样,后期维护十分困难 3). 项目生命周期十分短,项目生命没有延续性, ...

  4. check if a linux process is done using bash 检查进程是否在运行

    # cat > check_process_is_end.sh while truedo   sleep 30 # seconds   res=`ps -ef | grep RNAhybrid` ...

  5. python webdriver测试报告

    python webdriver测试报告 即将开始一系列的自动化项目实践,很多公共类和属性都需要提前搞定.今天,解决了测试报告的一些难题,参照了很多博文,最终觉得HTMLTestRunner非常不错, ...

  6. [ionic开源项目教程] - 第2讲 新建项目,配置app.js和controllers.js搭建基础视图

    新建项目 由项目功能架构图选择合适的页面架构,这里选用Tab,ionic新建项目,默认的模板就是tab. $ ionic start TongeNews Creating Ionic app in f ...

  7. Kafka的Producer和Consumer源码学习

    先解释下两个概念: high watermark (HW) 它表示已经被commited的最后一个message offset(所谓commited, 应该是ISR中所有replica都已写入),HW ...

  8. bdyyservice.exe 系统错误

    现象:开机出现 bdyyservice.exe 系统错误,说: 计算机中丢失log_report.dll 原因:安装百度影音,卸载后出现的问题 解决方法: 所有程序 -> 附件 -> 命令 ...

  9. UITableView中的(NSIndexPath *)indexPath

    indexPath 用来指示当前单元格,它的row方法可以获得这个单元格的行号,section方法可以获得这个单元格所处的区域号

  10. o4.数组指针和指针数组的区别

    ------- android培训.iOS培训.期待与您交流! ---------- 我们看一下数组指针和指针数组: 数组指针(也称行指针)定义 int (*p)[n];()优先级高,首先说明p是一个 ...