尝试将 SerialPort 输入打印到控制台

问题描述

首先是我的代码

#include <iostream>
#include <thread>
#using <System.dll>

using namespace System;
using namespace System::IO::Ports;
using namespace System::Threading;

int main()
{
    SerialPort^ mySerialPort = gcnew SerialPort("COM5");
    mySerialPort->Baudrate = 9600;
    mySerialPort->Parity = Parity::None;
    mySerialPort->StopBits = StopBits::One;
    mySerialPort->DataBits = 8;
    mySerialPort->Handshake = Handshake::None;
    mySerialPort->RtsEnable = true;

    while (1)
    {
        Console::WriteLine(Console::ReadLine());
    }
}

这个想法是从 SerialPort 读取并写入控制台。 Source

原本我打算使用:

std::cout << Console::ReadLine() << '\n';

但是,这有一个错误(ReadLine 输出 String^ 而不是 String,我不知道有什么区别),我希望能编译一些东西。

使用上面的代码我收到了错误: C++/CLI 不支持两阶段名称查找...使用 /Zc:twoPhase-

错误建议我使用 /Zc:twoPhase- 这是一个 compiler option。所以我启用它并得到错误: 元素具有无效值“Yes(/permissive-) /Zc:twoPhase-”

我不太确定如何从这里开始。

抱歉,我是一个初学者,我的头晕。任何帮助,将不胜感激! 注意:我包含了线程,我知道这段代码没有使用它,但我打算稍后使用它。

解决方法

根据“Element has an invalid value of "Yes(/permissive-) /Zc:twoPhase-"”判断你已经把这个编译器选项放在它不属于的地方。确保你知道它应该去哪里。例如。 Why do I have warning "C4199 two-phase name lookup is not supported for C++/CLI,C++/CX,or openmp"?

,

没有解决办法。我收到“无法打开文件 'MSCOREE.lib'”错误。该文件似乎不再存在于 Windows 中,我不知道如何获取它。所以我使用了 Visual Studio Windows Form App

编辑:eXCore 关于 .NET 框架的评论解决了这个问题。