با سلام
یه تابع با زبان c++ نوشتم که string رو توش includ کردم میخوام با ترمینال ران کنم این دستو رو میزنم
: gcc -o a $(mysql_config --cflags) a.cpp $(mysql_config --libs)
ولی توابعش رو نمیشناسه !!!این خطا رو میده
string’ was not declared in this scope
error: request for member ‘resize’ in ‘s’, which is of non-class type ‘char*’
چطور باید ران کنم؟؟
ممنون میشم اگه حل بشه
دستوراتی رو که گفتین رو هم اجرا کردم ولی باز هم خطا داد!در ضمن string .hرو میشناسه ولی string رو نه!!؟
این هم کد برنامه اس:
#include <my_global.h>
#include <mysql.h>
#include <openssl/md5.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(int argc, char **argv)
{
MYSQL *conn;
MYSQL_RES *result;
MYSQL_ROW row;
int num_fields;
int i;
string url="http://www.google.com/url?sa=t&rct=j&q=/source=web&cd=1&cad=/rja&ved=0CCkQFjAA&url=http://uploadpa.com";
string result=myhash(url);
int s=search(result);
while(!s)
{
//search again
url=spilit(url);
myhash(url);
s=search(result);
}
if(s)
{
//decisition
}
conn = mysql_init(NULL);
if(mysql_real_connect(conn, "localhost", "root", "*", "filtering", 0, NULL, 0))
printf("\nsucsess\n");
mysql_query(conn, "INSERT INTO `filtering`.`urllist` (`id` ,`url` ,`category`)VALUES (NULL , 'www.google.com', 'social')");
mysql_query(conn, "SELECT * FROM urllist");
result = mysql_store_result(conn);
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
for(i = 0; i < num_fields; i++)
{
printf("%s ", row ? row : "NULL");
}
printf("\n");
}
mysql_free_result(result);
mysql_close(conn);
return 0;
}
string myhash(string s)
{
unsigned string digest[16];
const string str="www.google.com";
printf("str length:%d\n",strlen(str));
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx,str,strlen(str));
MD5_Final(digest, &ctx);
string mdString[33];
for(int i=0;i<16;i++)
sprintf(&mdString[i*2],"%02x",(unsigned int)digest);
printf("md5 digest:%s\n",mdString);
return s;
}
int search(string h)
{
return 1;
}
string spilit(string s[])
{
bool flag=1;
int index;
while (flag)
{
index=s1.find("/");
if (s[index-1]=='/')
{
flag=1;
}
else
flag=0;
s.resize(index);
//cout<<"\n\n******** "<<s[index-1]<<"\n\n";
}
index=s.rfind("/");
s.resize(index);
return s;
}
واین هم خطاهایی که میده:
a.cpp: In function ‘int main(int, char**)’:
a.cpp:20:3: error: ‘string’ was not declared in this scope
a.cpp:20:10: error: expected ‘;’ before ‘url’
a.cpp:21:9: error: expected ‘;’ before ‘result’
a.cpp:22:21: error: ‘search’ was not declared in this scope
a.cpp:26:3: error: ‘url’ was not declared in this scope
a.cpp:26:17: error: ‘spilit’ was not declared in this scope
a.cpp:27:13: error: ‘myhash’ was not declared in this scope
a.cpp: At global scope:
a.cpp:59:1: error: ‘string’ does not name a type
a.cpp:75:12: error: ‘string’ was not declared in this scope
a.cpp:76:1: error: expected ‘,’ or ‘;’ before ‘{’ token
a.cpp:80:1: error: ‘string’ does not name a type
khadijeh@khadijeh-Inspiron-N5110:~/Downloads$