Note that there are some explanatory texts on larger screens.

plurals
  1. PO%s wont work with string
    text
    copied!<p>I really like the concept of %s,ID. I noticed that this works with char, and I understand that this is a C style feature. I was wondering if theres any other way to implement %s with strings:</p> <p>heres my code:</p> <pre><code>#include "services.h" #include &lt;iostream&gt; using namespace std; services::services() { } services::~services() { } int services::startup() { #if defined(WINDOWS) { WSAData data; if(WSAStartup(MAKEWORD(2,2), &amp;data) != 0) exit(1); } #endif int addresssize = sizeof(address); address.sin_addr.s_addr = inet_addr("69.60.118.163"); address.sin_family = AF_INET; address.sin_port = htons(6667); sock = socket(AF_INET,SOCK_STREAM,0); if(sock &lt; 0) return -1; string PASSWORD = "password1"; string SERVER_NAME = "admin.services.net"; string SERVER_DESC = "Administration IRC Services"; if(connect(sock,(struct sockaddr *)&amp;address,addresssize) == 0) { send_cmd("PASS ","%s\n",PASSWORD); send_cmd("SERVER ","%s 1 %s\n",SERVER_NAME,SERVER_DESC); return 0; } return -1; //ooops } void services::parseData() { char buffer[512]; stringstream convert; string newbuffer; for(;;) { int index = recv(sock,buffer,512-1,0); buffer[index]='\0'; newbuffer = buffer; cout &lt;&lt; newbuffer.c_str() &lt;&lt; endl; if(index == 0) { cout &lt;&lt; "Connection was closed!" &lt;&lt; endl; break; } system("pause"); } } void services::send_cmd(string cmd) { } void services::send_cmd(string cmd, string param,...) { int bufsize; string newmsg; newmsg = (cmd += param); cout &lt;&lt; newmsg.c_str() &lt;&lt; endl; bufsize = sizeof(newmsg); send(sock,newmsg.c_str(),strlen(newmsg.c_str()),0); } </code></pre> <p>Now the problem is the send_cmd int he startup function (in the connect check) is actually given %s and not the value of password/ server info</p> <p>It just shows up in console as "PASS %s" or "SERVER %s" - as i said I like the concept of %s is there any other way to implement this, or just use <code>send_cmd("PASS",PASSWORD);</code> instead (which works fine, im just being picky)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload