gpt4 book ai didi

c++ - error C3861 : '_T' : identifier not found , 无法将main函数参数作为函数参数传入

转载 作者:可可西里 更新时间:2023-11-01 16:59:16 27 4
gpt4 key购买 nike

我正在关注这个 guide关于使用 C++ 发送电子邮件。我按照说明操作,效果非常好

这是关于如何使用该程序发送电子邮件的示例代码,为了安全起见,我已经更改了电子邮件地址和密码

#include "stdafx.h"
#include <iostream>
#include "easendmailobj.tlh"
using namespace EASendMailObjLib;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize( NULL );

IMailPtr oSmtp = NULL;
oSmtp.CreateInstance( "EASendMailObj.Mail");
oSmtp->LicenseCode = _T("TryIt");

// Set your gmail email address
oSmtp->FromAddr = _T("randomemail1.lim@gmail.com");

// Add recipient email address
oSmtp->AddRecipientEx( _T("randomemail2s@hotmail.com"), 0 );

// Set email subject
oSmtp->Subject = _T("simple email from Visual C++ with gmail account");

// Set email body
oSmtp->BodyText = _T("this is a test email sent from Visual C++ project with Gmail");

// Gmail SMTP server address
oSmtp->ServerAddr = _T("smtp.gmail.com");

// If you want to use direct SSL 465 port,
// Please add this line, otherwise TLS will be used.
// oSmtp->ServerPort = 465;

// detect SSL/TLS automatically
oSmtp->SSL_init();

// Gmail user authentication should use your
// Gmail email address as the user name.
// For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
oSmtp->UserName = _T("somerandomemail@gmail.com");
oSmtp->Password = _T("somepassword");

_tprintf(_T("Start to send email via gmail account ...\r\n" ));

if( oSmtp->SendMail() == 0 )
{
_tprintf( _T("email was sent successfully!\r\n"));
}
else
{
_tprintf( _T("failed to send email with the following error: %s\r\n"),
(const TCHAR*)oSmtp->GetLastErrDescription());
}

if( oSmtp != NULL )
oSmtp.Release();

int x;
cin>>x;

return 0;
}

当我尝试将此代码复制粘贴到我的程序中并将其作为我可以使用的函数时,出现以下错误

error C3861: '_T': identifier not found 

这就是我的函数的样子

void DriverClass::send_email(int argc, _TCHAR* argv[])
{
::CoInitialize( NULL );

IMailPtr oSmtp = NULL;
oSmtp.CreateInstance( "EASendMailObj.Mail");
oSmtp->LicenseCode = _T("TryIt");

// Set your gmail email address
oSmtp->FromAddr = _T("randomemail1.com");

// Add recipient email address
oSmtp->AddRecipientEx( _T("randomemail2@hotmail.com"), 0 );

// Set email subject
oSmtp->Subject = _T("simple email from Visual C++ with gmail account");

// Set email body
oSmtp->BodyText = _T("this is a test email sent from Visual C++ project with Gmail");

// Gmail SMTP server address
oSmtp->ServerAddr = _T("smtp.gmail.com");

// If you want to use direct SSL 465 port,
// Please add this line, otherwise TLS will be used.
// oSmtp->ServerPort = 465;

// detect SSL/TLS automatically
oSmtp->SSL_init();

// Gmail user authentication should use your
// Gmail email address as the user name.
// For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
oSmtp->UserName = _T("randomemail1@gmail.com");
oSmtp->Password = _T("randompassword");

_tprintf(_T("Start to send email via gmail account ...\r\n" ));

if( oSmtp->SendMail() == 0 )
{
_tprintf( _T("email was sent successfully!\r\n"));
}
else
{
_tprintf( _T("failed to send email with the following error: %s\r\n"),
(const TCHAR*)oSmtp->GetLastErrDescription());
}

if( oSmtp != NULL )
oSmtp.Release();

int x;
cin>>x;


}

我认为这与我无法将 int argc_TCHAR*argc[] 作为参数传递有关,如何将其变成函数我可以使用哪个以及如何解决它???

最佳答案

添加:

#include <tchar.h>

因为那是定义_T(和_TCHAR)宏的地方。参见 Generic-Text Mappings in Tchar.h .

关于c++ - error C3861 : '_T' : identifier not found , 无法将main函数参数作为函数参数传入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21623347/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com