How to print a particular word/string from a file in c++

from the attachmet i need to print the output as

1.       class.User                                                                  

2.                                             (mvè Member Variable)

srikar gajawadaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertFabrice LambertCommented:

I don't see any attachment...
You need to print, on the standard output or on a printer ?

On standard output, you'll need the "<<" operator:
std::string myData{"random text."};
std::cout << myData << std::endl;

Open in new window

To print a class, you'll probably need to overload the "<<" operator (according that make a sens of course).

Without seeing your class design or source code, I can't advice any further.
srikar gajawadaAuthor Commented:
please find the attachment for more info
Fabrice LambertFabrice LambertCommented:
You should provide the header also.

From what I see so far:
The constructor must initialize the UserID member, as creating a user without ID make no sens.
The constructor must initialize a default password, again creating a user without password make no sens. In consequence, the parameter-less constructor should not exist.
The setUserId member function shouldn't exist, changing a user ID make no sens.
The user class have an entity semantic, thus should not be copyable neither assignable. This is done by deleting the copy constructor and assignment operator.
Getters should be const qualified.
Parameters that shouldn't be modified should be const qualified.
Do not use the directive "using namespace std". It's sole purpose was maintain old code base when namespaces were introduced in C++ (back in 1990). Today, there is no reason to use it, as it is a potential source of name conflicts and ambiguities.

To print the class, you either call its services to retrieve user datas (but password, as printing it make no sens) or overload the << operator.
Code below with operator overload.

#include <iostream>
#include <string>

class User
	std::string UserId;
	std::string UserPassword;
	User(std::string const& userID);	    // constructor
	User(User const&) = delete;           // copy constructor deleted.
	~User();						   // destructor
	User& operator=(User const&) = delete;    // assignment operator deleted.
	const std::string& getUserId() const;           // getters
	const std::string& getUserPassword() const;
	void setUserPassword(std::string const& userPassword);  // setter
	friend std::ostream& operator<<(std::ostream& os, User const& user);    // operator << overload

Open in new window

#include "User.h"

	// constructor, initialize member via initialisation list.
User::User(std::string const& userID): UserId{userID},
	std::cout << "\n User class constructor was called\n";

	// destructor
	std::cout << "\n User class destructor was called\n";

	// getters (const qualified)
const std::string& User::getUserId() const
	return UserId;

const std::string& User::getUserPassword() const
	return UserPassword;

    // setter
void User::setUserPassword(std::string const& userPassword)
	this->UserPassword = userPassword;

    // operator << overload
std::ostream& operator<<(std::ostream& os, User const& user)
    os << user.UserId;
    return os;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fabrice LambertFabrice LambertCommented:
No answer from asker.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.