How to remove from the variable string f, a piece of text located between the k-th characters '\ n'? That is, for example, string f = "111232 \ naaaaaaa \ n245642aaaa2 \ n21582". And I need a piece of text between 2 and 3 characters '\ n', that is, "245642aaaa2". And you need to write it to another variable of type string.
1 answer
As it turned out in the discussion, the problem is actually deeper: in the function that collects this very line. Rewrite this function like this:
vector<string> Connect( char host[], char user[], char password[], char database[], int port, int unix_socket, int clientflag) { //"localhost", "root", "12345", "farabi4", NULL, NULL, 0 vector<string> results; MYSQL *conn; // <-- нужно инициализировать, в вашем коде этого нет MYSQL_RES *res = mysql_store_result(conn); if (res) { MYSQL_ROW row; while (row = mysql_fetch_row(res)) { for (i = 0; i < mysql_num_fields(res); i++) results.push_back(row[i]); } } else fprintf(stderr, "%s\n", mysql_error(conn)); mysql_close(conn); return results; } (By the way, where was the string l before? And where conn ?)
Then you need to save the whole vector<string> instead of string , and access the necessary elements by index.
- conn = mysql_init (NULL); mysql_query (conn, "SELECT path FROM src2"); // Make a request to the table string l = ""; - user200355
- Thank you very much, it turned out :) - user200355
- @ user200355: That's great! You are welcome! - VladD
|
vector<string>? - VladDvector<string>and return it fromConnect. - VladD