Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:13:57+00:00 2026-06-06T22:13:57+00:00

I’m trying to convert integer data to string , but I’m getting error cannot

  • 0

I’m trying to convert integer data to string , but I’m getting error cannot convert 'int*' to 'const char*' for argument '2' to 'char* strcat(char*, const char*)'

hey guys please fix these issue, where did I dowrong?

    #include <iostream>
    using namespace std;
    #include "sqlite3.h"
    #include<string.h>
    #include <sstream>
    #define STRING_MAX 32

    typedef struct metadata_t
    {
      char session_username[256];   
      int user_id[256];
      int session_id[256];
      char buffer[256];
    }metadata_t;

    void  insertdata1(metadata_t *data);

  int main (int argc, const char * argv[])
      {

      struct metadata_t *data;
        cin >> *data->user_id;
        cin >> data->session_username;
        cin >> *data->session_id;
        cin >> data->buffer;


         insertdata1(data);

         }

    void insertdata1(metadata_t *data)
        {

         // char *buff1,*buff2;
             sqlite3 *db;
             sqlite3_open("test1.db", & db);
             string createQuery = "CREATE TABLE IF NOT EXISTS items (user_id INTEGER PRIMARY KEY,   session_username TEXT,Session_id INTEGER,buffer TEXT,));";
             sqlite3_stmt *createStmt;
             cout << "Creating Table Statement" << endl;
             sqlite3_prepare(db, createQuery.c_str(), createQuery.size(), &createStmt, NULL);
             cout << "Stepping Table Statement" << endl;
             if (sqlite3_step(createStmt) != SQLITE_DONE) cout << "Didn't Create Table!" << endl;


            //itoa(*data->userid,buff1,10);  // not work
            //itoa(*data->userphone,buff2,10);// Integer to String Conversion

        /*   std::string  ss;
           ss << *data->user_id;
           ss << *data->session_id;
           std::string user_Id = ss.str();
           std::string session_Id = ss.str();  */ // not working
                   char *a="(";
                   char *d=")";
                   char *b="'";
                   char *c=",";
                   char str1[1000];
                   char * str2 = "";
                   char * g = ";"; 
               strcpy(str1, "INSERT INTO items (user_id,session_username,session_id,buffer)VALUES");

               strcat(str1,a);

               strcat(str1,b);
               strcat(str1,data->user_id);
               strcat(str1,b);
               strcat(str1,c);
               strcat(str1,b);
               strcat(str1,data->session_username);
               strcat(str1,b);
               strcat(str1,c);
               strcat(str1,b);
               strcat(str1,data->session_id);
               strcat(str1,b);
               strcat(str1,c);
               strcat(str1,b);
               strcat(str1,data->buffer);
               strcat(str1,b);
               strcat(str1,d);
               strcat(str1,g);

            std::string insertQuery = str1; // WORKS!
            sqlite3_stmt *insertStmt;
            cout << "Creating Insert Statement" << endl;
            sqlite3_prepare(db, insertQuery.c_str(), insertQuery.size(), &insertStmt, NULL);
            cout << "Stepping Insert Statement" << endl;
            if (sqlite3_step(insertStmt) != SQLITE_DONE) cout << "Didn't Insert Item!" << endl;




      }** 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:13:58+00:00Added an answer on June 6, 2026 at 10:13 pm

    Recommend using a std::ostringstream (you need to #include <sstream>) to construct your query:

    std::ostringstream str1;
    
    str1 << "INSERT INTO items (user_id,session_username,session_id,buffer)VALUES"
         << a
         << b // and so on
         << g;
    
    const std::string insertQuery = str1.str();
    

    The following does not allocate any memory, but just declares a pointer (the struct is not required in C++):

    struct metadata_t *data;
    

    and any attempt to dereference it will result in undefined behaviour, most likely a segmentation fault:

    cin >> *data->user_id; 
    

    just declare it on the stack:

    metadata_t data;
    

    and pass it’s address (or pass by reference) to insertdata1():

    insertdata1(&data);
    

    Prefer std::string to char* or char[]:

    struct metadata_t
    {
        std::string session_username;
        int user_id[256];  // Did you really mean an array of int here ?
        int session_id[256];
        std::string buffer;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.