Question: Basically what I want to do is to load a string from a file that is to be encoded as a json. 

The way I have achieved this is quite verbose for what should be a simple operation:

```
std::ifstream t(json_path);

std::string stringbuf = std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());

boost::erase_all(stringbuf, "\t");

boost::erase_all(stringbuf, "\n");

boost::erase_all(stringbuf, " ");

```

Is there a briefer way to load a text file to a string and strip out the special characters?

Answer: 
You can also use `std::copy_if` and an inserting iterator to copy only the characters that you want instead of copying everything, shuffling the bytes around (e.g., `std::remove_if`), and removing the ones that you don't want.

```
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>

int
main(int argc, char **argv)
{
    std::string outbuf;
    std::ifstream ins(argv[1]);
    std::copy_if(std::istreambuf_iterator<char>(ins),
                 std::istreambuf_iterator<char>(),
                 std::back_insert_iterator<std::string>(outbuf),
                 [](char c) { return !std::isspace(c); });
    std::cout << outbuf << std::endl;
    return 0;
}

```
You can do that in that way:

```
inFile.open(fileName, ios::in); 

if(inFile.fail()) {
    cout<<"error opening the file.";
} else {
    getline(inFile,paragraph);
    cout << paragraph << endl << endl;
}

numWords=paragraph.length();

while (subscript < numWords) {
    curChar = paragraph.substr(subscript, 1);
    if(curChar==","||curChar=="."||curChar==")"
        ||curChar=="("||curChar==";"||curChar==":"||curChar=="-"
        ||curChar=="\""||curChar=="&"||curChar=="?"||
        curChar=="%"||curChar=="$"||curChar=="!") {
        paragraph.erase(subscript, 1);
        numWords-=1;
    } else {
        subscript+=1;
    }
}

cout<<paragraph<<endl;
inFile.close();

```