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();

Recommended Answers

All 6 Replies

What are some of the methods that strings have that you can use?

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.