微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C++/CLI System.FormatException: '输入字符串的格式不正确'同时将系统字符串转换为 int

如何解决C++/CLI System.FormatException: '输入字符串的格式不正确'同时将系统字符串转换为 int

我正在制作一个鼠标,我是用我的 arduino 制作的,我正在通过串行端口将数据(x,y,以及按钮是否被按下(我的数据看起来像这样:x234y256s0)发送到c++/cli 控制台应用程序(CLR)。我成功地将数据传递给 cli,然后我将数据转换为 std::string,然后将该字符串分成 3 个字符串 x、y 和 s,然后我想将那些 { {1}} 转换为整数,我首先需要将它们转换为系统字符串(String^),这也成功了,然后我尝试将其转换为这样的整数:std::strings(稍后将显示我的整个代码),那行给了我这个错误

int X = System::Convert::ToInt32(x1);

此外,我在代码 System.FormatException: 'Input string was not in a correct format.' 的末尾添加了这一行,该行给了我 2 个错误

SetCursorPos(mouseX,mouseY);

我真的不知道这两个错误是什么意思,我以前从未使用过 CLI,而且我很少使用 C++。

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2028 unresolved token (0A0001DE) "extern "C" int __stdcall SetCursorPos(int,int)" (?SetCursorPos@@$$J18YGHHH@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z) arduinoSerial2  C:\.....    1   and
Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "extern "C" int __stdcall SetCursorPos(int,int)" (?SetCursorPos@@$$J18YGHHH@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)  arduinoSerial2  C:\.....    1,

解决方法

试试:int i = int::Parse(str); // string to int

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。