I have just started to write a server and client for an assignment but can't get my client code to compile. The server compiles just fine using just the boost library but in my client code I am using boost and ncurses.
I am using g++ battleship_client.cc -lboost_system -lncurses
when trying to compile.
I have googled like crazy but I haven't found a solution. I should also note that I am on a mac and that I am using vscode. I have changed my includePath to look like this:
"includePath": [
"${workspaceFolder}/**",
"/usr/local/Cellar/boost/1.68.0_1/",
"/usr/local/Cellar/ncurses/6.1/"
],
battleship_client.cc:
#include <iostream>
#include <string>
#include <vector>
#include <ncurses.h>
#include <boost/asio.hpp>
using namespace std;
using boost::asio::ip::tcp;
void draw_top_matrix(vector<vector<int> > &board, int cur_row, int cur_col) {
for (int j=0;j<4;j++) {
move(0,2*j);
printw("+-");
}
move(0,2*4);
printw("+");
for (int i=0;i<4;i++) {
for (int j=0;j<4;j++) {
move(2*i+1,2*j);
printw("|");
move(2*i+1,2*j+1);
if (board[i][j] == 0) {
printw(" ");
}
else {
printw("X");
}
}
move(2*i+1,2*4);
printw("|");
for (int j=0;j<4;j++) {
move(2*i+2,2*j);
printw("+-");
}
move(2*i+2,2*4);
printw("+");
}
move(2*cur_row+1,2*cur_col+1);
}
void init(vector<vector<int> > &board) {
int rows;
int cols;
int cur_row = 0;
int cur_col = 0;
for(int i = 0; i < 4; i++) {
vector<int> temp;
for(int j = 0; j < 4; j++) {
temp.push_back(0);
}
board.push_back(temp);
}
initscr();
clear();
getmaxyx(stdscr, rows, cols);
cbreak();
keypad(stdscr, TRUE);
refresh();
draw_top_matrix(board, 0, 0);
endwin();
}
int main(int argc, char *argv[]) {
int port = atoi(argv[3]);
vector<vector<int> > board;
boost::asio::io_service my_service;
tcp::resolver resolver(my_service);
tcp::socket socket(my_service);
socket.connect(tcp::endpoint(boost::asio::ip::address::from_string(argv[2]), port));
init(board);
return 0;
}
The errors I am getting:
In file included from battleship_client.cc:4:0:
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:595:7: error: 'stdscr' is not a type
int timeout() const
^
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:595:7: error: expected identifier before ')' token
int timeout() const
^
/usr/local/include/boost/asio/basic_socket_streambuf.hpp: In member function 'std::basic_streambuf<char>::int_type boost::asio::basic_socket_streambuf<Protocol, Clock, WaitTraits>::underflow()':
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:479:42: error: expected primary-expression before ')' token
socket().native_handle(), 0, timeout(), ec_) < 0)
^
/usr/local/include/boost/asio/basic_socket_streambuf.hpp: In member function 'std::basic_streambuf<char>::int_type boost::asio::basic_socket_streambuf<Protocol, Clock, WaitTraits>::overflow(std::basic_streambuf<char>::int_type)':
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:538:42: error: expected primary-expression before ')' token
socket().native_handle(), 0, timeout(), ec_) < 0)
^
/usr/local/include/boost/asio/basic_socket_streambuf.hpp: In member function 'void boost::asio::basic_socket_streambuf<Protocol, Clock, WaitTraits>::connect_to_endpoints(EndpointIterator, EndpointIterator)':
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:656:39: error: expected primary-expression before ')' token
socket().native_handle(), timeout(), ec_) < 0)
ncurses.h defines timeout
as preprocessor macro. Try adding NCURSES_NOMACROS
define
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.