LibTorch与MFC

LibTorch与MFC

#include <afxwin.h>
#include "resource.h"
#include<opencv2/opencv.hpp>
#include <torch/torch.h>
#include <torch/script.h> 
#include <afxwin.h>
using namespace std;
class MyFrameWnd :public CFrameWnd {
	// 类内声明宏
	DECLARE_MESSAGE_MAP()
public:
	LRESULT OnCreate(WPARAM wParam, LPARAM IParam);
};

// 类外实现宏
BEGIN_MESSAGE_MAP(MyFrameWnd, CFrameWnd)
	ON_MESSAGE(WM_CREATE, OnCreate)
END_MESSAGE_MAP()

class MyWinApp :public CWinApp {
public:
	MyWinApp() {

	}
	virtual BOOL InitInstance() {

		MyFrameWnd* pFrame = new MyFrameWnd;
		pFrame->Create(NULL, "Test");
		m_pMainWnd = pFrame;
		pFrame->ShowWindow(SW_SHOW);
		pFrame->UpdateWindow();
		return TRUE;
	}
};

MyWinApp mainApp;

// 测试
LRESULT MyFrameWnd::OnCreate(WPARAM wParam, LPARAM IParam) {

	torch::Tensor b = torch::tensor({ 999 });
	int a = b[0].item().toInt();
	string str = to_string(a);
	AfxMessageBox(str.c_str());
	return 0;
}

在这里插入图片描述

补充

int转string

std::string s = std::to_string(42);

tensor转换成int c++/libtorch

torch::Tensor b = torch::tensor({ 999 });
int a = b[0].item().toInt();

string转CString

string str = "test"
c_str = str.c_str(); //注意这里使用的是 =运算符的重载

CString转string

多字节编码下:

string str = c_str.GetBuffer();

Unicode编码下:

CString c_str = _T("li");
//CT2A将Unicode转换为多字符集ASCII
std::string str = CT2A(c_str.GetString()); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值