no matching function for call to ‘isdigit(std::__cxx11::string&)’

this is my code

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
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <cstdlib>

using namespace std;

int get_file (ifstream& in, ofstream& out, string filename, string output);
void get_line (ifstream& in, ofstream& out, string filename, string output);

int main () {
ifstream in;
ofstream out;
string filename, output;
get_file (in, out, filename, output);
get_line (in, out, filename, output);
}
int get_file (ifstream& in, ofstream& out, string filename, string output) {
        cout << "enter the file you would like to open" << endl;
        cin >> filename;
        in.open (filename.c_str());
        if (!in.fail()) {
               cout << "that is not a file" << endl;
               return 0;
        }
        cout << "Input the name of the output file" << endl;
        cin >> output;
        out.open (output.c_str());
        if (!in.fail()) {
                cout << "that is not a file" << endl;
                return 0;
        }
}
void get_line (ifstream& in, ofstream& out, string filename, string output) {
        string line;
        int size = 10000;
        string words[size];
        while (!in.eof()){
                for (int i = 0; i < size; i++) {
                        getline (in, words[size]);
                        if (isdigit(words[i])) {
                                out << "*";
                        }
                }
        }
}

im trying to replace stuff in a file when i compile i get the error that is in the title of this post.
Last edited on
words[] is an array of strings and so each element is a string, hence:
 
 if (isdigit(words[i]))
checks if the entire string isdigit() whereas you want to check if an individual element of the string isdigit
thankyou for the reply but how would i go about doing that because i thought thats what getline did was go through each element individually.
 i thought thats what getline did was go through each element individually.

afraid not, in this case all that getline() does is read the input file, in, line by line into a std::string and then you have to check whether or not each of these strings read in contain any digits. Following link will give you some ideas and I'm there are others:
http://stackoverflow.com/questions/2346599/how-to-test-if-a-string-contains-any-digits-in-c
thats why i put it into an array im trying to have each element in the array be a character or number from the input file does that not work?
plus thanks for the link and help
Topic archived. No new replies allowed.