如何在C ++中将int转换为wchar_t *? [英] How to concat an int to a wchar_t* in C++?
本文介绍了如何在C ++中将int转换为wchar_t *?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须创建和写入N个文件,每个人都必须以整数结尾来标识它.
I have to create and write on N files, everyone must have an integer ending to identificate it.
这是我的代码:
for(int i=0; i<MAX; i++)
{
uscita.open("nameFile"+i+".txt", ios::out);
uscita << getData() << endl;
uscita.close();
}
这就是我想要在执行后在目录中找到的内容:
And that's what I would like to find in my directory after execution:
nameFile0.txt
nameFile1.txt
nameFile2.txt
...
nameFileMAX.txt
上面的代码的问题是我得到了编译错误:
The problem of the above code is that I get the compilin' error:
错误C2110:'+'无法添加两个指针
error C2110: '+' Impossible to add two pointers
如果我尝试为该名称创建一个字符串,则会出现另一个问题:
If I try to create a string for the name, another problem comes in:
string s ="nameFile"+i+".txt";
uscita.open(s, ios::out);
问题是:
错误C2664:您无法从字符串转换为
const wchar_t*
我该怎么办?如何创建具有不同名称的文件,将int
包含为wchar_t*
?
What can I do? How can I create files with different names concating int
to wchar_t*
?
推荐答案
您可以使用wstringstream
std::wstringstream wss;
wss << "nameFile" << i << ".txt";
uscita.open(wss.str().c_str(), ios::out);
这篇关于如何在C ++中将int转换为wchar_t *?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文