Hi guys, i currently want to replace all spaces into another(or 2) special character, and vice versa. e.g (replacing spaces with 'xx' character and vice versa). Another way would be removing all spaces completely. Is there any method i can use to accomplish that?

#include <iostream>

#include <vector>

#include <fstream>

#include <algorithm>

#include <ctime>

#include "stdlib.h"
using namespace std;
                        string plaintext;
			ifstream infile;
			infile.open ("Plaintext.txt");
        		while(!infile.eof()) // To get you all the lines.
        		{
	       			 getline(infile,plaintext); // Saves the line in STRING.
	        		 cout<<plaintext; // Prints our STRING.
        		}
			infile.close();

im guessing string::replace? but how do i exactly incorporate it.

use the return of <string>.find(<char*>) to get the position of the space
use <string>.replace(<int>,<int>,<char*>) to replace
and use string::npos to check if a match is found

any template i can draw examples from?

You own mind. What do you do when you need to do the task at your desk with paper and pencil. Write down those steps and find string methods that mimic them.

This article has been dead for over six months. Start a new discussion instead.