gpt4 book ai didi

c++ - 将 TCHAR 数组中的数值存储到 VC++ 中的 INTEGER 变量中。 (在 UNICODE 环境中)

转载 作者:行者123 更新时间:2023-11-28 08:01:46 25 4
gpt4 key购买 nike

我在帖子中问了一个非常相似的问题: https://stackoverflow.com/questions/11259474/store-the-numericals-in-char-array-into-an-integer-variable-in-vc

W.R.T.上面的线程,我的问题如下::我在 UNICODE 环境中工作。所以 TCHAr 可能会被视为 wchar。

我的场景如下:(C++)

In TCHAR a[10], the array a[] has elements (numbers) like '1','2','3' etc....

Say a[0] = '1'; a1 = '2'; a[2] = '3';

Now a[] is storing 3 characters '1', '2' and '3'. I want to store this into an int as 123 (An integer 123).

How to achieve this in C++ ?

提前致谢。

最佳答案

首先,您必须以 null 终止您的字符串。否则,你怎么知道在哪里停下来?然后有一个专门用于此的函数 _ttoi()

a[3] = 0;
int n = _ttoi[a];

你必须了解空终止位。根据您如何用字符(数字)填充 a,确定字符串结尾的逻辑可能会有所不同。

关于c++ - 将 TCHAR 数组中的数值存储到 VC++ 中的 INTEGER 变量中。 (在 UNICODE 环境中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11265498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com