Verwirrendes Verhalten von C ++ String Returns und C_str () Gießt [Duplikat] aus.C++

Programme in C++. Entwicklerforum
Anonymous
 Verwirrendes Verhalten von C ++ String Returns und C_str () Gießt [Duplikat] aus.

Post by Anonymous »

Ich bin neu bei C ++ - Programmierung (meist mit Java arbeiten), und dieses Verhalten von C ++ - Klassen, Mitgliedszeichenfolgen und String -Conversions zu const char* mit c_str () verwirrt mich.

Sample.h < /p>

Code: Select all

class Sample
{
private:
int id;
std::string text;
public:
Sample(int id);
void setId(int id);
int getId();
void setText(std::string txt);
std::string getText();
void loadText();
~Sample();
}
< /code>

 Sample.cpp[/b]

Sample::Sample(int id)
{
this->id = id;
}

void Sample::setId(int id)
{
this->id = id;
}

int Sample::getId()
{
return this->id;
}

void Sample::setText(std::string txt)
{
this->text = txt;
}

std::string Sample::getText()
{
return this->text;
}

void Sample::loadText()
{
this->text = "Loaded";
}

Sample::~Sample()
{
std::cout loadText();
const char* text = sample->getText().c_str();
std::cout getText();
const char* text = textCpy.c_str();
std::cout

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post