What is wrong here?

Okay so I am making a small application to be used in large text files that have useless data. So all the data after the first space on each line gets deleted. i have worked all the compilation errors out except one. Here is the source.

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
// extract.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	string x;
	cout << "Enter file name" << endl;
	cin >> x;
	fstream file;
	file.open(x.c_str()); // open file
	if(file) 
	{
		ofstream out("data.txt");
		if(!out) 
		{ 
		cout << "Cannot open or create file."; 
		return 2; 
		} 
 
		string s="";
		char* lookfor = " ";
		while(!file.eof())
		{
			while(getline(file,s))
			{
				if (lookfor != NULL)
				{
				
					out << s.peek;
				}
			
			}
		}   
	}
		
	else
	{
		cout << "Error opening file.";
		return 1;
	}
	return 0;
}


Here is my error

1
2
3
4
5
6
7
8
error C2039: 'peek' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'

1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Ax=std::allocator<char>
1>          ]
In class string there is no variable named peek, as the compiler error says.... You could take a look at that:http://www.cplusplus.com/reference/string/string/

I think you must code it for yourself

regards
Topic archived. No new replies allowed.