FBIagent
Erfahrenes Mitglied
Wie im Betreff schon gesagt: Wenn ich mein kompiliertes Programm starte beendet es
mit einem Fehler nach der eingabe. Hier der code:
main.cpp
conection.h:
Woran könnte es liegen das ich bei oder nach der eingabe ( cin >> input_str; ) diesen
Fehler bekomme?
Ich würde gerne den datentyp 'String' benutzen anstatt 'char*' aber damit hatte ich
nur ärger.
THX im Vorraus
MFG FBIagent
EDIT:
Für char* jetzt den Typ String genommen. Jetzt habe ich einen Fehler:
mysql_real_connect();
will nen char* haben.
Wie bekomm ich einen std::string in einen char*?
mit einem Fehler nach der eingabe. Hier der code:
main.cpp
Code:
#include <iostream>
#include <windows.h>
#include <mysql/mysql.h>
#include <conio.h>
#include "conection.h"
using namespace std;
char *msg[5];
char *input_str;
int input_int;
con_info conection;
MYSQL my_sql;
void init()
{
msg[0] = "Hostname/IP";
msg[1] = "Port";
msg[2] = "Username";
msg[3] = "Password";
msg[4] = "Database";
for(int i=0;i<5;i++)
{
cout << msg[i] << ": ";
switch(i)
{
case 0:
cin >> input_str;
conection.set_host(input_str);
input_str = NULL;
case 1:
cin >> input_int;
conection.set_port(input_int);
input_int = 0;
case 2:
cin >> input_str;
conection.set_user(input_str);
input_str = NULL;
case 3:
cin >> input_str;
conection.set_pass(input_str);
input_str = NULL;
case 4:
cin >> input_str;
conection.set_db(input_str);
input_str = NULL;
}
}
if(mysql_real_connect(&my_sql,conection.get_host(),conection.get_user(),conection.get_pass(),conection.get_db(),conection.get_port(),NULL,0))
{
cout << "Verbindung wurde hergestellt.";
Sleep(1000);
}
else
{
cout << "Verbindung konnte nicht hergestellt werden!";
cout << conection.get_host() << "\n";
cout << conection.get_port() << "\n";
cout << conection.get_user() << "\n";
cout << conection.get_pass() << "\n";
cout << conection.get_db() << "\n";
}
}
int main(int argc, char *argv[])
{
init();
getch();
return 0;
}
Code:
// the class
class con_info
{
private:
char* host;
int port;
char* user;
char* pass;
char* db;
public:
void set_host(char* data);
void set_port(int data);
void set_user(char* data);
void set_pass(char* data);
void set_db(char* data);
char* get_host();
int get_port();
char* get_user();
char* get_pass();
char* get_db();
};
// set infos
void con_info::set_host(char* data)
{
host = data;
}
void con_info::set_port(int data)
{
port = data;
}
void con_info::set_user(char* data)
{
user = data;
}
void con_info::set_pass(char* data)
{
pass = data;
}
void con_info::set_db(char* data)
{
db = data;
}
// get infos
char* con_info::get_host()
{
return host;
}
int con_info::get_port()
{
return port;
}
char* con_info::get_user()
{
return user;
}
char* con_info::get_pass()
{
return pass;
}
char* con_info::get_db()
{
return db;
}
Woran könnte es liegen das ich bei oder nach der eingabe ( cin >> input_str; ) diesen
Fehler bekomme?
Ich würde gerne den datentyp 'String' benutzen anstatt 'char*' aber damit hatte ich
nur ärger.
THX im Vorraus
MFG FBIagent
EDIT:
Für char* jetzt den Typ String genommen. Jetzt habe ich einen Fehler:
mysql_real_connect();
will nen char* haben.
Wie bekomm ich einen std::string in einen char*?
Zuletzt bearbeitet: