我对 C++ 非常陌生,并且已经尝试自学了几天。如果我的问题很明显或以前被问过,我提前道歉,我已经多次寻找解决方案,我似乎看到的所有解决方案都比我的直觉告诉我需要的更复杂,而且通常超出我的想象。 ..无论如何,对于我的问题的长篇介绍感到抱歉:
我只是试图根据来自多项选择问题的输入来确定 wchar_t 数组(它只是一个 unicode 字符串?)的值(或者我猜值......数组仍然有点可怕)。
到目前为止,这是我所做的:
#include "stdafx.h"
#include <iostream>
#include <string>
#include "easendmailobj.tlh"
using namespace EASendMailObjLib;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int MAX = 65;
//char server[MAX], serverName[MAX], userName[MAX], password[MAX], from[MAX], to[MAX], msg[160];
//Choosing a SMTP server
int choice = 0;
bool logon = true;
bool ssl = true;
cout << "1)Gmail\n"
<< "2)Yahoo\n"
<< "3)Hotmail\n"
<< "4)None (Experemental)\n"
<< "5)Other (Advanced)\n"
<< "What kind of E-mail would you like to send from?:";
cin >> choice;
switch(choice) {
case 1: wchar_t server[] = _T("smtp.gmail.com");
char serverName[] = "Gmail";
break;
case 2: wchar_t server[] = _T("smtp.mail.yahoo.com");
char serverName[] = "Yahoo";
ssl = false;
break;
case 3: wchar_t server[] = _T("smtp.live.com");
char serverName[] = "Hotmail";
break;
case 4: wchar_t server[] = _T("");
logon = false;
ssl = false;
break;
case 5: cout << "Enter your server:";
char server[MAX];
wcin.getline(server, MAX, '\n');
cout << "Does your server require a login? (true or false):";
cin >> logon;
cout << "Does your server require an SSL connection? (true or false):";
cin >> ssl;
break;
default: cout << endl <<"You entered a wrong number, restart, and try again."
<< endl;
}
}
这似乎一切都很好,但是当我尝试编译时,它会抛出关于多次声明同一个变量的各种错误,我有点明白,但每个人都应该根据选择运行,对吗?我会先声明所有内容,然后根据选择进行定义,但是根据我所读到的内容,这在 C++ 中是不可能的。
我真的被困在这里,非常感谢您的耐心和帮助。