Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // klasse in einer *.cpp Datei. Nicht zu empfehlen!
- #include <iostream>
- #include <string>
- #include <sstream>
- class meineKlasse {
- private:
- int i1;
- public:
- std::string name;
- void setName(int i, std::string name)
- {
- this->i1 = i;
- this->name = name;
- }
- std::string getName()
- {
- std::string eingabe;
- std::cout << "Bitte Name eingeben: ";
- getline(std::cin, eingabe);
- return (eingabe);
- }
- void inkrement(); // vordeklaration
- std::string getData(); // vordeklaration
- };
- void meineKlasse::inkrement()
- {
- i1++;
- }
- std::string meineKlasse::getData() // klasse von ausserhalb erweitern
- {
- // notwendig, um string & int in einen streamstring zu packen
- std::stringstream sstr;
- sstr << name << " ID: " << i1;
- return (sstr.str());
- }
- int main()
- {
- meineKlasse cls;
- std::string n;
- n = cls.getName();
- cls.setName(1, n);
- cls.inkrement();
- std::cout << "Name: " << cls.getData() << std::endl;
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement