A little help with functions

Can someone help me with making this look nice before I turn my project in?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;

int main()
{
ifstream in_file;
string fileName, text, words, test;
stringstream buffer;

int counter = 0;

    cin >> fileName;

    in_file.open(fileName.c_str());
    if(in_file.fail())
    {
        cout << "Can't open file" << endl;
        exit(1);
    }

    while(!in_file.eof())
    {
        in_file >> text;
    }
    in_file.close();

    text.erase(std::remove(text.begin(), text.end(), '.'), text.end());
    text.erase(std::remove(text.begin(), text.end(), ','), text.end());
    text.erase(std::remove(text.begin(), text.end(), '!'), text.end());
    text.erase(std::remove(text.begin(), text.end(), '?'), text.end());
    text.find_last_of(" ");

    in_file.open(fileName.c_str());
    while(!in_file.eof())
    {
        buffer << in_file.rdbuf();
        test = buffer.str();

        getline(in_file, words);
    }
    in_file.close();

    size_t pos = 0;
    while(true)
    {
        pos = test.find(text, pos);
        if (pos != std::string::npos)
        {
            counter++;
            pos++;
        }
        else break;
    }
    cout << text << " " << counter;
    return 0;
}
I tried it this way, but i get one error in it that I don't understand. Would this be ok and you wanna find the error? Or do you guys gave any better idea?

My code trying with functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;

void erasee(string text_m);
void buffer(ifstream in_file_m, string filename_n);

int main()
{
ifstream in_file;
string fileName, words, test, text;
stringstream buffer;

int counter = 0;

    cin >> fileName;

    in_file.open(fileName.c_str());

    if(in_file.fail())
    {
        return 0;
    }

    while(!in_file.eof())
    {
        in_file >> text;
    }
    in_file.close();

    erasee(text);
    buffer(in_file, fileName);

    size_t pos = 0;
    while(true)
    {
        pos = test.find(text, pos);
        if (pos != std::string::npos)
        {
            counter++;
            pos++;
        }
        else break;
    }
    cout << text << " " << counter;
    return 0;
}

void erasee(string text_m)
{
    string text;

    text.erase(std::remove(text.begin(), text.end(), '.'), text.end());
    text.erase(std::remove(text.begin(), text.end(), ','), text.end());
    text.erase(std::remove(text.begin(), text.end(), '!'), text.end());
    text.erase(std::remove(text.begin(), text.end(), '?'), text.end());
    text.find_last_of(" ");
}

void buffer(ifstream in_file_m, string filename_n)
{
    stringstream buffer;
    string test, words, fileName;
    ifstream in_file;

    in_file.open(fileName.c_str());
    while(!in_file.eof())
    {
        buffer << in_file.rdbuf();
        test = buffer.str();

        getline(in_file, words);
    }
    in_file.close();
}


The error = cplusplus 1 m functions\main.cpp|36|error: no match for call to '(std::stringstream {aka std::basic_stringstream<char>}) (std::ifstream&, std::string&)'|
Topic archived. No new replies allowed.