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

//题目描述
//
//描述:
//输入一个整数,将这个整数以字符串的形式逆序输出
//程序不考虑负数的情况,若数字含有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. Database: Normal form

    refer to wikipedia--- 1NF(first normal form): 1. There's no top-to-bottom ordering to the rows. 2. T ...

  2. Docker入门命令

    Edit Docker入门命令 # 安装镜像sudo docker pull ubuntu:12.04# 镜像列表sudo docker images# 运行镜像sudo docker run -t ...

  3. Couchbase 找回登录密码

    在项目里,我们使用Couchbase当做缓存层,效果非常好,支持集群与数据监测,可悲的有一次我新建了一个服务器,安装完成Couchbase之后,密码忘了! 怎么也想不起来,Couchbase又没有提供 ...

  4. Machine Learning for hackers读书笔记(十)KNN:推荐系统

    #一,自己写KNN df<-read.csv('G:\\dataguru\\ML_for_Hackers\\ML_for_Hackers-master\\10-Recommendations\\ ...

  5. 部署新浪SAE web.py Session及图片上传等问题注意事项

    1.以下几条代码解决编码问题 import sysreload(sys)sys.setdefaultencoding('utf-8') 2.图片上传问题 需要开通sina的Storage服务,随便建个 ...

  6. iOS XMPP Framework 中文概述

    本篇文章翻译XMPP Framework中的Overview of the XMPP Framework部分 介绍 The framework is divided into 2 parts: 1. ...

  7. codevs 4919 线段树练习4

    线段树水题.我是ziliuziliu,我是最强的#include<iostream> #include<cstdio> #include<cstring> #inc ...

  8. UVALive 5532 King(差分约束,spfa)

    题意:假设一个序列S有n个元素,现在有一堆约束,限制在某些连续子序列之和上,分别有符号>和<.问序列S是否存在?(看题意都看了半小时了!) 注意所给的形式是(a,b,c,d),表示:区间之 ...

  9. Scala List

    1 介绍 Scala中列表List类似于数组,List所有元素都具有相同的类型,但有两个重要的区别. 首先,列表是不可变的,这意味着一个列表的元素可以不被分配来改变. 第二,列表表示一个链表,而数组平 ...

  10. 文件IO

    在unix世界中视一切为文件,无论最基本的文本文件还是网络设备或是u盘,在内核看来它们的本质都是一样的.大多数文件IO操作只需要用到5个函数:open . read . write . lseek 以 ...