Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

couldn't replace string taken as input from user

0 votes
asked Jun 13, 2020 by Islamic videos (120 points)
void update_staff(){
	int x; // stores output when finds id matching index.
	string id, name, newn; //newn = new name;
	fstream fin; // fin = file in output mode.
	cout << "Enter id of member: " << endl;
	cin >> id;
	fin.open("Member.csv", ios:: out); // here file is opened in output mode. 
		getline(fin, name); //String from file to name is stored.
		x = name.find(id);
		if( x == -1){   // when no nothing found then -1 is stored in integer type variable.
			cout << "Name not found! " << endl;
			cout << "Name founded! " << endl;
			cout << "Enter new name: ";
			getline(cin, newn);
			string.replace(newn, name);
	fstream file;
		file.open("Updated Member.csv", ios:: app);
		 file << newn;
			} // end of above if statement
} // ending of function.

1 Answer

0 votes
answered Jun 14, 2020 by gameforcer (2,950 points)

name.replace(0, newn.length(), newn);

This replaces 'name' with 'newn', starting at position 0 (first sign)..

If you need more then read the documentation about replace.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.