我在这个地方有错误:
cd ~/Downloads
wget http://downloads.sourceforge.net/project/pyqt/PyQt5/PyQt-5.7/PyQt5_gpl-5.7.tar.gz
tar xf PyQt5_gpl-5.7.tar.gz
cd PyQt5_gpl-5.7
python configure.py --qmake ~/Qt/5.7/gcc_64/bin/qmake --disable QtPositioning --no-qsci-api --no-designer-plugin --no-qml-plugin --confirm-license
make -j 5
sudo make install
错误是:
strcpy_s(msgToGraphics, game.board_now());
这是game.board_now func:
IntelliSense: no instance of overloaded function "strcpy_s" matches the argument list argument types are: (char [1024], std::string)
以下是我尝试使用string Board::board_now()
{
return _board;
}
的其余代码:
strncpy_s()
代码基本上用于国际象棋程序,我尝试在我做出更改后收到国际象棋棋盘,我不知道如何在#include "Pipe.h"
#include "Board.h"
#include <iostream>
#include <thread>
using namespace std;
void main()
{
srand(time_t(NULL));
Pipe p;
bool isConnect = p.connect();
string ans;
while (!isConnect) {
cout << "cant connect to graphics" << endl;
cout << "Do you try to connect again or exit? (0-try again, 1-exit)" << endl;
cin >> ans;
if (ans == "0") {
cout << "trying connect again.." << endl;
Sleep(5000);
isConnect = p.connect();
}
else {
p.close();
return;
}
}
char msgToGraphics[1024];
// msgToGraphics should contain the board string accord the protocol
// YOUR CODE
Board game;
//strcpy_s(msgToGraphics, game.board_now()); // just example...
p.sendMessageToGraphics("rnbkqbnrpppppppp################################PPPPPPPPRBNKQNBR0"); // send the board string
// get message from graphics
string msgFromGraphics = p.getMessageFromGraphics();
while (msgFromGraphics != "quit") {
game.change_board(msgFromGraphics);
game.change_board_sq(msgFromGraphics);
strcpy_s(msgToGraphics, game.board_now()); // msgToGraphics should contain the result of the operation
// return result to graphics
p.sendMessageToGraphics(msgToGraphics);
// get message from graphics
msgFromGraphics = p.getMessageFromGraphics();
}
p.close();
}
中格式化他以便将他放入阵列并发送给它回到给定的exe。
答案 0 :(得分:1)
最简单的解决方案是将msgToGraphics
设为std::string
,然后不要使用C函数strcpy_s
,只需指定它来执行相同的操作:
msgToGraphics = game.board_now();
如果您需要为基础数组获取非常量char*
,您可以这样做(通常需要注意):
p.sendMessageToGraphics(&msgToGraphics[0]);
但实际上你应该改变界面,不要依赖传入的char数组。(提示:改为使用std::string
。)
答案 1 :(得分:1)
由于C11 strcpy_s
1) `char *strcpy( char *dest, const char *src );`
2) errno_t strcpy_s(char *restrict dest, rsize_t destsz, const char *restrict src);
strcpy_s 与(1)相同, 除了它可能用未指定的值破坏目标数组的其余部分,并且在运行时检测到以下错误并调用当前安装的约束处理函数:
null
指针strnlen_s(src, destsz);
换句话说,会发生截断重叠会在源字符串和目标字符串之间发生
如果dest&lt; = strnlen_s(src, destsz) < destsz;
指向的字符数组的大小,换句话说,destsz的错误值不会暴露即将发生的缓冲区溢出,则行为是未定义的。
作为所有边界检查函数,strcpy_s
仅在实现定义__STDC_LIB_EXT1__
且用户将__STDC_WANT_LIB_EXT1__
定义为整数常量1时保证可用在包括string.h
。
有关详情,请参阅此页面http://en.cppreference.com/w/c/string/byte/strcpy