Error with void

Mar 26, 2017 at 6:49am
I am a beginner in C++ and I am attempting to write a code. However, after writing the code I was told that there is an error stating "error: variable or field 'replace_string' declared void". But I can't seem to understand where the error is and how I can remove that error. Would really appreciate some help. Thank you ><


This is my main function
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
#include <string>
#include <fstream>
#include <iostream>

void replace_string(string&, string, string);

using namespace std;

int main()
{
    ifstream text;
    text.open("original.txt");

    ofstream edited;
    edited.open("corrected.txt");

    string stringline;

    while(getline(text,stringline))
    {
        replace_string(stringline,"ung","in");
        cout<<stringline<<endl;
    }

    text.close();
    edited.close();

}


And here is my function code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <string>

using namespace std;

void replace_string(string& str, string str0,string str1)
{
    int i,str0size;

    str0size=str0.size();

    do
    {
        i=0;
        if (str.find(str0,0)!=4294967295)
        {
            str.insert(str.find(str0,0),str1);
            str.erase(str.find(str0,0),str0size);
            i=1
        }
    }
    while(i==1);
}
Mar 26, 2017 at 7:09am
move the function header below "using namespace std"

the header uses string, and you don't call it std::string in the code, so it has to go below the using statement!

also, I=1; <------ missing ;

Mar 26, 2017 at 7:27am
omg thanks a lot >< that's such a silly mistake from me. >< Thanks!
Topic archived. No new replies allowed.