Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么这个代码不影响输出?_C++ - Fatal编程技术网

C++ 为什么这个代码不影响输出?

C++ 为什么这个代码不影响输出?,c++,C++,这将接收输入并将每个字母1向右移动。暂停会阻止它做任何事情吗 我如何更改它,使其不只是输出用户输入的内容 这是Visual Studio社区2013中C++中的代码: #include "stdafx.h" #include <iostream> using namespace std; #include <string> #include <cctype> int _tmain(int argc, _TCHAR* argv[]) { string

这将接收输入并将每个字母1向右移动。暂停会阻止它做任何事情吗

我如何更改它,使其不只是输出用户输入的内容

这是Visual Studio社区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;
    }
}
#包括“stdafx.h”
#包括
使用名称空间std;
#包括
#包括
int _tmain(int argc,_TCHAR*argv[]
{
字符串密码;
cout>cyphertext;
无效加密(字符*密码文本,无符号整数偏移量);
for(int i=0;cyphertext[i]!=0;i++){
char firstLetter=islower(cyphertext[i])?“a”:“a”;
无符号整数alphaOffset=cyphertext[i]-第一个字母;
整数偏移=0;
无符号整数newAlphaOffset=alphaOffset+offset;
cyphertext[i]=第一个字母+新字母偏移量%26;

cout您的
暂停
在“加密”循环内。它需要在循环外。循环内的
返回
将终止程序;这也需要在循环外

请注意,当代码缩进到正统的布局中(如现在讨论的布局)时,更容易看到此类错误。使用潦草的布局会使代码布局整齐时很难看到许多明显的问题


您还可以声明一个从未使用过的函数
encrypt()
;不要这样做。通常,在其他函数中声明函数是个坏主意。而且考虑到没有
encrypt()函数
function defined,没有“void function”,因此我为您更改了问题标题。

这段代码似乎没有实际编译…很容易确定暂停的效果-删除该行并再次运行程序。但为什么要声明一个名为“encrypt”的函数你从未定义或使用过它?虽然我怀疑它与你的问题有关,但你将
offset
设置为0,然后立即在
newAlphaOffset=alphaOffset+offset
中使用它,这是故意的吗?Zenzelezz,有一个错误表明offset未定义。这就是我为什么这么做的原因。