c++ - 错误没有运算符 ">>"匹配这些操作数

标签 c++ cin

我正在尝试编写一个程序,通过电子邮件将文本消息发送到我的手机,我已经完成了 smtp 和所有爵士乐的处理,所以技术部分已经完成,它可以工作,我只想成为能够在程序中输入我要发送的正文/消息;这就是我所拥有的:

int choice;
cout << "Welcome\n 1:send a text message\n 2:quit\n";
cout << "type either 1 or 2: ";
cin >> choice;
if (choice == 1)
{
const char* message;
cout << "What would you like to send?: ";
cin >> message;

我在 if 语句中设置了邮件发送

mail.SetLogin("******");
mail.SetPassword("********");
mail.SetSenderName("****");
mail.SetSenderMail("***@gmail.com");
mail.SetReplyTo("");
mail.SetSubject("text");
mail.AddRecipient("******@tmomail.net");
mail.SetXPriority(XPRIORITY_NORMAL);
mail.SetXMailer("The Bat! (v3.02) Professional");
mail.AddMsgLine(message);

我收到一条错误消息说 = Error no operator ">>"matches these operands 操作数类型是 std::istream >> const* char

我知道我在为消息设置变量时搞砸了,它正在 #include 库中寻找它,如果有人知道如何解决这个问题,我将非常感激。

顺便说一句,我现在拥有的#includes 是

#include "CSmtp.h"
#include <iostream>
#include <Windows.h>

最佳答案

没有 >>> 重载将文本流式传输到 const char *。而是使用 std::string

关于c++ - 错误没有运算符 ">>"匹配这些操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37342225/

相关文章:

c++ - boost::shared_array<char> 到 std::string

c++ - Clang 3.5.0 std::wregex 编译错误

c++ - Cin 和 Cout 不工作

c++ - 为什么 cin >> string 不能与 Visual C++ 2010 一起使用?

c++ - 手动设置 cin.fail()

c++ - std::to_string 不是使用 CygWin 的 C++11 中的成员

c# - 扫描文档中背景/前景层的分离

C++从一个数组添加到另一个数组,每次我向另一个数组添加元素时查看另一个数组

c++ - 如何让用户输入两次以上?

c++ - istream_iterator eos