为什么这段代码不影响输出?
Why is this code not affecting the output?
这应该接受输入并将每个字母向右移动1。暂停会阻止它做任何事情吗?
我怎样才能改变它,使它不只是输出用户输入的内容?
这是Visual Studio Community 2013中的c++代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <string>
#include <cctype>
int _tmain(int argc, _TCHAR* argv[])
{
string cyphertext;
cout << "Paste your cyphertext and press enter to shift right 1: ";
cin >> cyphertext;
void encrypt(char * cyphertext, unsigned int offset);
for (int i = 0; cyphertext[i] != 0; i++) {
char firstLetter = islower(cyphertext[i]) ? 'a' : 'A';
unsigned int alphaOffset = cyphertext[i] - firstLetter;
int offset = 0;
unsigned int newAlphaOffset = alphaOffset + offset;
cyphertext[i] = firstLetter + newAlphaOffset % 26;
cout << "" << "Right One: " << cyphertext;
system("pause");
return 0;
}
}
您的pause
在'加密'循环内。它需要在外面。循环中的return
将终止程序;这也需要在循环之外。
请注意,当代码在正统的布局中缩进时,更容易看到这样的错误,比如现在的问题。使用粗糙的布局使得很难发现许多问题,而这些问题在代码布局整齐时是很明显的。
你还声明了一个从未使用过的函数encrypt()
;不要那样做。在函数内部声明函数通常不是一个好主意。鉴于没有定义encrypt()
函数,没有'void函数',所以我为您更改了问题标题。
相关文章:
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 为什么fflush(stdin)对输出没有影响
- 3D 纹理大小会影响程序输出,而不会引发错误
- 没有代码的内联函数会影响输出的二进制
- 为什么将 std::endl 与 ostringstream 一起使用会影响输出速度
- printf输出不受全局区域设置的影响
- iomanip意外影响ctime函数输出
- 使用运算符[]访问一个函数中的字符串会影响C++中另一个函数的输出
- 位操作符的优先级对输出的影响
- 为什么这段代码不影响输出?