无法在开关大小写中调用函数 - C++

Can't Call Function Within Switch Case - C++

本文关键字:调用 函数 C++ 大小写 开关      更新时间:2023-10-16

我正在尝试运行某种加密程序,但我无法通过开关函数调用void enc, 源代码:

#include <iostream>
#include <conio.h>
#include <windows.h>
#include <algorithm>
#include <string>
using namespace std;
int x,y,z,a,b,c,n;
char tabs[26][26],temp[512];
string input,output,Key;
void open();
void tableau();
void inchar();
void enc();
void dec();
int main() {
open();
cout << "1.tEncrypt n2.tDecrypt nOption: "; cin >> a;
switch (a) {
case 1:
enc(); cout << a << "Debugger";
break;
case 2:
dec();
break;
}
return 0;
}
void enc(){
void open();
void inchar();
}
void dec(){
}
void inchar(){
cout << "input: "; cin >> input; z = input.size();
char dispos[input.size() + 1];
copy(input.begin(),input.end(),dispos); dispos[input.size()] = '';
for (int i = 0; i < z; i++) {
temp[i] = dispos [i];
}
}
void tableau() {
cout << "Initialize Table Construct!!" << endl;
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
x = (i + j) % 26; y = x + 65;
tabs[i][j] = y;
cout << tabs[i][j] << " ";
}
cout << endl;
}
}
void open() {
cout << "Well Hello There";
}

每次我选择选项 1 时,调试器 cout 都会不断出现。 如果调试器被擦除,则代码就会结束。

PS:我已经完成了将函数调用移动到切换之前,但它仍然什么也没做。 PS:对不起,英语不好。

问题是你的enc()函数调用了,但它什么也没做!语法错误:

void enc(){
void open();   // These lines DECLARE two NEW function ...
void inchar(); // ... without ever calling them!
}

要调用这两个函数,请使用以下命令:

void enc(void) {
open();
inchar();
}