作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我要创建和写入N个文件,每个文件都必须以整数结尾来标识它。
这是我的一段代码:
for(int i=0; i<MAX; i++)
{
uscita.open("nameFile"+i+".txt", ios::out);
uscita << getData() << endl;
uscita.close();
}
这就是我想在执行后在我的目录中找到的内容:
nameFile0.txt
nameFile1.txt
nameFile2.txt
...
nameFileMAX.txt
上面代码的问题是我得到了编译错误:
error C2110: '+' Impossible to add two pointers
如果我尝试为名称创建一个字符串,则会出现另一个问题:
string s ="nameFile"+i+".txt";
uscita.open(s, ios::out);
问题是:
error C2664: you cannot convert from string to
const wchar_t*
我能做什么?如何创建具有不同名称的文件,将 int
连接到 wchar_t*
?
最佳答案
你可以使用std::to_wstring
:
#include <string>
// ...
std::wstring s = std::wstring("file_") + std::to_wstring(i) + std::wstring(".dat");
(如果您需要 C 风格的 wchar_t*
,则使用 s.c_str()
。)
关于c++ - 如何在 C++ 中将 int 连接到 wchar_t*?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8609842/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!