0

How I can write one or more objects that contain a string in a same file?

I tried to write a object like: #include <iostream> #include <string> using namespace std; class object { private: string something; long int anything; public: object (string likethis, long int bored){ this -> something = likethis; this -> anything = bored; } }; and tried to write 5 object of this class in a file, but don't load all of the attrbutes. I tried without a string, and works. And I tried to with a string like this: char myString[20], and works. So, how I can do this with a

6th Feb 2017, 12:22 AM
JoĂŁo Victor Oliveira Couto
JoĂŁo Victor Oliveira Couto - avatar
2 Answers
0
If you don't use 'using namespace std;' you need std:: before each 'string' (std::string).
6th Feb 2017, 12:05 AM
Robobrine
Robobrine - avatar
0
Oh, missed this the first time, you should make the constructor public.
6th Feb 2017, 12:20 AM
Robobrine
Robobrine - avatar