我不明白我的代碼在這裏有什麼問題。我創建了一個名爲pause()的函數,其中一切似乎都沒問題,但編譯器正在捕獲錯誤。 另一個問題是,當我運行代碼並選擇選項1時,它會轉到選項1,但不會執行任何其他操作,因爲有更多的代碼是爲它編寫的。請運行下面給出的代碼並讓我知道。我正在使用代碼塊。 請幫我解決。謝謝。爲什麼我的代碼沒有編譯?
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cstdlib>
#include <windows.h>
using namespace std;
#define size 550000;
class morsecode{
private:
string text;
char msg[10001];
public:
void choose();
void convert();
void translate();
void exit();
void pause(int p){
for(int i=0;i<p;i++){
for(long int j=0;j<size;j++){
}
}
}
};
void morsecode::choose(){
system("CLS");
cout << "1.Convert message\n";
cout << "2.Translate message\n";
cout << "3.Exit\n";
cout << "\nEnter the number you want to choose:";
int a;
cin >> a;
if(a==1){
convert();
}
else if(a==2){
translate();
}
else if(a==3){
exit();
}
else{
system("CLS");
cout << "Wrong input\n";
pause(3);
choose();
}
}
void morsecode::convert(){
system("CLS");
cout << "Enter the message you want to convert to morse code:\n\n";
getline(cin,text);
int len=text.length();
cout << len;
}
void morsecode::translate(){
;
}
void morsecode::exit(){
;
}
int main(){
morsecode obj1;
obj1.choose();
cout << "\n\n\n\n\n";
return 0;
}
如果不編譯它,你如何運行你的代碼? – chtz
編譯器不會發現錯誤。要麼有錯誤,並且程序沒有創建,或者有警告。請先顯示警告。 – starturtle
另外:爲什麼你混合使用'std :: cout'和'getline'?有'std :: in'來代替'getline'和'printf'來代替'std :: cout' - 如果你希望下週再次訪問你的代碼,你會希望選擇一個概念並堅持下去。 – starturtle