关于组合字符串的初学者问题 [英] Beginner question about combining string

查看:69
本文介绍了关于组合字符串的初学者问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试编写一些简单的程序来学习C ++中的Windows编码,

Hello, i'm trying to write some simple program to learn windows coding in C++,

我遇到过一个问题,并尝试搜索库的解决方案,但遗憾的是没有找到一个。

I've encountered a problem and tried searching the library for a solution but sadly have not found one.

当创建一个窗口,其中有一个父窗口输入文本我想组合文本,我的代码是如下:

When creating a window that has a parent window to input text i would like to combine text, my code is as follows:

int GetWindowStat = 0;



GetWindowStat = GetWindowText(TextBoxCo,coValInput,20);
$


:: MessageBox(hwnd,coValInput,L"移动到:",MB_OK);

int GetWindowStat = 0;

GetWindowStat = GetWindowText(TextBoxCo, coValInput, 20);

::MessageBox(hwnd, coValInput, L"Moving to:", MB_OK);

在messageBox中你可以看到coValInput变量,我希望它能不仅显示这个值,而且还有一些文字在其前面。

in the messageBox u can see the coValInput variable, i would like it to not only display this value but have some text infront of it.

所以不要说它例如10我想要它说"移动到10"

So instead of it saying for example 10 i'd like it to say "moving to 10"

我尝试使用L"移动到:" .. coValInput 和&NBSP; L"移动到:" << coValInput和L"移动到:" + coValInput但所有这些都给我错误。

I tried using L"Moving to: "..coValInput  and  L"Moving to: " << coValInput and also L"Moving to: " + coValInput but all of these give me errors.

谢谢!

推荐答案

嗯:

std::wstring message(50, L'\0'); //this is the constructor that allocates all of the memory up front and fills it with a specific character, this is to avoid the reallocation

message = L"Moving to: "; //extra space at the end to separate

GetWindowText(wnd, str, 20);
message += str;
MessageBox(wnd, message.c_str(), L"Moving to:", MB_OK);

当然你必须包含< string>以及其他标题。

Of course you would have to include <string> along with the other headers.

您必须转到标准库的原因是因为C ++没有内置字符串类型。在设计它时,他们认为它可以作为标准库的一部分工作,而不必构建到语言中。

The reason why you have to go to the standard library is because C++ doesn't have an inbuilt string type. When designing it, they decided that it would work just as well being part of the standard library and didn't have to be built into the language.


这篇关于关于组合字符串的初学者问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆