header for space and not_space

hi,
I get the following error, does that mean I am missing a header?
if so, can you please tell me which one. thx!
 
error: ‘space’ was not declared in this scope
You are trying to use a variable/symbol names space which isn't in the scope you are currently in.
hi Zhuge,

this is my code. how can I correct it to fix the error.

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
#include <fstream>
#include <iostream>
#include <iterator>
#include <algorithm>

#include <string>
#include <cctype>
#include <vector>

using namespace std;

vector<string> split2(const string &);

int main()
{
 std::string pfile="test.txt";
 std::ifstream infile; 
 infile.open(pfile.c_str());
 std::string line;

  if(infile)
    {
      while(getline(infile,line))
        {  
	   vector<string>v=split2(line);
	    for(vector<string>::size_type i=0; i!=v.size(); ++i)
	   cout<<v[i]<<endl;
	}
    }
 return 0;
}

vector<string> split2(const string &str)
{
  typedef string::const_iterator iter;
  vector<string>ret;

  iter i=str.begin();

  while(i!=str.end())
    {
      i=find_if(i,str.end(),not_space);

      iter j=find_if(i,str.end(),space);

      if(i!=str.end())
	ret.push_back(string(i,j));
      i=j;
    }
  return ret;
}
closed account (1vRz3TCk)
Add the following?
1
2
3
4
5
6
7
8
bool space(char c)
{
    return isspace(c);
}
bool not_space(char c)
{
    return !space(c);
}
Last edited on
thanks CodeMonkey
Topic archived. No new replies allowed.