【发布时间】:2015-10-29 09:34:30
【问题描述】:
我正在使用Visual studio 2015 通过C++ 构建一个通用应用程序;
当我想将Textbox->Text 转换为float 类型时。我搜索谷歌,但没有解决。我不能使用TryParse or Convert:: or float.parse。
这是我的Mainpage.cpp的用法
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
我不能使用System::。当我写它时显示syntax error
【问题讨论】:
-
您正在编写纯本机代码,不能使用 .NET Framework 命名空间或方法。如果您更喜欢转换为 wstring,请使用普通的 C++ 转换函数,例如
_wtof(someString->Data)或 stod()。 -
感谢您的回复。我这样写: float a = _wtof(textBox->Text->Data);并得到一个错误 C3867: 'Platform::String::Data': non-standard syntax;使用 App1(我的项目名称)'&' 创建指向成员的指针。我该如何解决?
-
Data是一个方法,所以使用Data() -
哦,我的错!谢谢@PeterTorr-MSFT