如何写入 wstring 数组中的特定位置
How do I write to a specific position in a wstring array?
我有一个名为map的wstring,想要写入该wstring数组中的特定位置。我能够从特定位置读取字符,但除了附加到它之外,我不知道如何写入此字符串。
float fPlayerX;
float fPlayerY;
int nMapWidth = 16;
int nMapHeight = 16;
bool GotO;
wstring map
map += L"################";
map += L"#G.............X";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#..............#";
map += L"#......O.......#";
map += L"#..............#";
map += L"#..............#";
map += L"################";
if (map.c_str()[(int)fPlayerX * nMapWidth + (int)fPlayerY] == 'O')
{
// Pick up O
if (GotO == false)
{
// WRITE A "." TO WHERE THE O IS RIGHT NOW
}
}
如果我尝试
map[(int)fPlayerX * nMapWidth + (int)fPlayerY] = L".";
或
map[(int)fPlayerX * nMapWidth + (int)fPlayerY] = ".";
我得到
Error C2440 '=': cannot convert from 'const wchar_t [2]' to 'wchar_t'
您可以使用 map[index] = '.'
,其中 index 是您计算的位置。
小心使用 '
而不是"
!表达式 '.'
的类型为 char,而 "."
实际上表示数组{'.', ' '}
并且类型为 char const *
。
相关文章:
- 将值指定给向量(2D)的向量中的某个位置
- 使用Unreal C++获取VR耳机的世界位置/方向
- 写入位置0x0000000C时发生访问冲突
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 如何使用cudaMallocManaged在指针位置初始化对象?(C++)
- 无法获取webot::PositionSensor对象中位置传感器的值
- 非常量变量只读位置的赋值
- 如何定义更改car类中car位置的方法
- 使用迭代器时如何访问对象在向量中的位置?
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 求最大元素位置的分治算法
- 你好。。。id_public变量不应该给出结果为 81 和 86 吗?为什么它为两个派生类占用不同的内存位置?
- 是与初始类同一内存位置的重新定位类
- 如何在使用网格布局时重叠qwidgets,并将重叠的widget定位在距离窗口边界特定距离的位置
- 我不知道如何定位最高随机数的位置
- 如何在MFC上设置窗口位置以将其定位到屏幕顶部
- 将QGraphicsSvgItem的中心定位在一个位置上。
- 如何定位WinRT异步方法调用中出现错误的位置
- 重定位表项在平面二进制文件中的存储位置