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

//题目描述
//
//描述:
//输入一个整数,将这个整数以字符串的形式逆序输出
//程序不考虑负数的情况,若数字含有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. python公司面试题集锦 python面试题大全

    问题一:以下的代码的输出将是什么? 说出你的答案并解释. class Parent(object): x = 1 class Child1(Parent): pass class Child2(Par ...

  2. python中的类简单讲解

    类似其它的语言, Python 中的函数使用小括号( () )调用.函数在调用之前必须先定义.如果函数中没有 return 语句, 就会自动返回 None 对象.      Python 是通过引用调 ...

  3. Volley HTTP库系列教程(3)自定义RequestQueue和编写单例RequestQueue示例

    Setting Up a RequestQueue Previous  Next This lesson teaches you to Set Up a Network and Cache Use a ...

  4. Introduction

    http://www.entityframeworktutorial.net/EntityFramework5/entity-framework5-introduction.aspx Basics o ...

  5. This project needs to migrate WTP metadata

    in command-line: path> mvn eclipse:clean path> mvn -Dwtpversion=1.5 eclipse:eclipse path> m ...

  6. 漫游Kafka实现篇之分布式

    Zookeeper节点标记 当路径中的元素包括在方括号里比如[xyz],则表示xyz表示的值是不固定的,每个可能的值都有一个Zookeeper节点.比如/topics/[topic]表示每个topic ...

  7. laravel5 centos6.4下的配置体验

    1. 安装lmnp环境: nginx version: nginx/1.6.0. php 5.5.7 . centos6.42. laravel-v5.1.4 一键安装包,在使用composer 安装 ...

  8. Python [Leetcode 345]Reverse Vowels of a String

    题目描述: Write a function that takes a string as input and reverse only the vowels of a string. Example ...

  9. 【英语】Bingo口语笔记(62) - 生气道歉场景的表达

  10. 学习macos常用的一些快捷键笔记

    学习mac 操作系统使用笔记 Dock功能学习 类似快捷图标一样 Command+q quit a program Dock上添加与删除都用拖动 command+delete 删除文件 shift+c ...