小编Rob*_*t J的帖子

While 循环出现意外的 bash 退出

问题陈述:

while当我使用时,我似乎遇到了循环问题set -e

 1  #!/bin/bash
 2  # This is a script to perform initial configurations of CentOS 7.2
 3  # Written by Robert J.
 4  
 5  # Exit if unexpected condition
 6  set -e;
 7  
 8  # Simple die function
 9  dieaquickdeath(){
10      code=$1;
11      message=$2;
12      printf "$message\n";
13      exit "$code";
14  }
15  
16  #
17  ## There is an initial prompt here that was removed for simplification.
18  #
19  InputPassword1=1
20  InputPassword2=2
21 …
Run Code Online (Sandbox Code Playgroud)

bash

2
推荐指数
1
解决办法
1429
查看次数

在C++中使用find和replace超出界限

我似乎遇到了一个奇怪的情况,我不会在C++中.当我执行一个解析和替换字符串的函数(罗马数字).如果字符串不存在,我最终会超出界限:

终端输出:

Mac Shell: CPP/>$ ./Roman2Num 

Retrieving input: 
------------------
Enter a number: 24
input: XXIV
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string
Abort trap: 6
Mac Shell: CPP/>$ ./Roman2Num 

Retrieving input: 
------------------
Enter a number: 29
input: XXVIV
Roman: XXIX 
Mac Shell: CPP/>$ ./Roman2Num 

Retrieving input: 
------------------
Enter a number: 1999
input: MDCDLXLVIV
Roman: MDCDLXLIX 
Mac Shell: CPP/>$ ./Roman2Num 

Retrieving input: 
------------------
Enter a number: 1998
input: MDCDLXLVIII
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string
Abort …
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
153
查看次数

标签 统计

bash ×1

c++ ×1