Attempting to read data from a file line by line

I am entirely new to programming in C++ but have coded to a reasonable extent within python. I am attempting to compile the following code but receive the following errors:

histogram1.cpp: In function ‘int main()’:
histogram1.cpp:14: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::open(std::string&)’
/usr/include/c++/4.4/fstream:525: note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode)[with _CharT = char, _Traits = std::char_traits<char>]
histogram1.cpp:63: error: ‘pos’ was not declared in this scope
histogram1.cpp:108: error: ‘tile_counter’ was not declared in this scope
histogram1.cpp:128: error: ‘limits’ was not declared in this scope
histogram1.cpp:132: error: expected ‘;’ before ‘upper_x_limit’
histogram1.cpp:142: error: ‘begin_hist’ was not declared in this scope
histogram1.cpp:147: error: ‘end_hist’ was not declared in this scope
histogram1.cpp:169: error: expected ‘;’ before ‘}’ token


The code is:
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <fstream>
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{

const string ws = " \t"; //going to be used to test input

string filename = "wbbj.top"; //will need to obtain this from elsewhere eventually
ifstream inwards; //initialise the opening if the file
inwards.open(filename);
if( !inwards.good() ) //test to see if the file can be opened
	{
	cerr << "Cannot open the file: \"" << filename+"\"!" << endl;
	abort(); //if it can't then print an error and abort
	}

//initialise the variables
string line("");
string title_a("");
string title_b("");
string title_c("");
string title_d("");
string left_title("");
string top_title("");
string bottom_title("");
string lower_x_limit("");
string upper_x_limit("");
string scale("");
int new_plot_switch = 0;
int loc_0;
int loc_1;
int loc_2;
int loc_3;
int loc_4;
int loc_5;
int loc_6;
int loc_7;
int loc_8;
int loc_9;
int loc_10;
int loc_11;
int loc_12;
int loc_13;
int title_counter = 0;


while( getline(inwards, line)) { //whilst there are still lines from the file to read
//	line=""; //initialise line to be empty
//	inwards >> line; //take the line from the file
//	cout << "line inputted: " << line << endl; //print the inputted line to the screen

	std::string::size_type loc_0 = line.find_first_not_of(ws); // find the first non whitespace element
	if(std::string::npos == loc_0) //if the line is empty then just continue
	{ 
	continue;
	}
	else //If the line has text, then erase all whitespace up to that text
	{
        line.erase(0, pos);
	}

	// Find the location of all the important strings if they're there
	loc_1 = line.find( "SCALE", 0 );
	loc_2 = line.find( "TITLE", 0 );
	loc_3 = line.find( "SET LIMITS", 0);
	loc_4 = line.find( "title", 0);
	loc_5 = line.find( "BEGIN HIST", 0);
	loc_6 = line.find( "END HIST", 0);
	loc_7 = line.find( "NEW PLOT", 0);	
	
	//test to see if anything interesting has been found
	if (std::string::npos != loc_1) //If the line contains the y-axis scale
		{
		scale = line.substr(12); //extract just the scale used
		continue; //Once this line has been identified then we can move on with the next line 
		}
	else if (std::string::npos != loc_2) //If the line contains one of the TITLES
		{
		loc_8 = line.find( "TOP", 0); //find the location of all the relevant strings
		loc_9 = line.find( "BOTTOM", 0);
		loc_10 = line.find( "LEFT", 0);
		loc_11 = line.find( "SET TITLE", 0);
		if (std::string::npos != loc_8) //If the line contains the TITLE TOP
			{
			top_title = line.substr(10);
			continue;
			}
		else if (std::string::npos != loc_9) //If the line contains the TITLE BOTTOM
			{
			bottom_title = line.substr(13);
			continue;
			}
		else if (std::string::npos != loc_9) //If the line contains the TITLE LEFT
			{
			left_title = line.substr(11);
			continue;
			}
		else if (std::string::npos != loc_11) //If the title doesnt contain anything interesting
			{
			continue;
			}
		else 
			{
			tile_counter++;
			if (title_counter == 1)				
				{				
				title_a = line.substr(14);
				continue;
				}
			else if (tile_counter = 2)
				{
				title_b = line.substr(14);
				continue;
				}
			else
				{
				title_c = line.substr(14);
				continue;
				}
			}
		}
	else if (std::string::npos != loc_3)//If the line contains the limits of the x-axis
		{
		limits = line.substr(16);
		loc_12 = limits.find_last_of(ws);
		loc_13 = limits.find_first_of(ws);
		lower_x_limit = limits.erase(loc_13, limits.end())
		upper_x_limit = limits.erase(0, loc_12+1)
		continue;
		}
	else if (std::string::npos != loc_4) //If the line contains the title
		{
		title_d = line.substr(23);
		continue;
		}
	else if (std::string::npos != loc_5) //If the line contains the BEGIN HIST marker
		{
		begin_hist++;
		continue;
		}
	else if (std::string::npos != loc_6) //If the line contains the END HIST marker
		{
		end_hist++;
		continue;
		}
	else if (std::string::npos != loc_7) //If the line contains the NEW PLOT marker
		{
		new_plot_switch = 1;
		cout << "Histogram Title A: " << title_a << endl;
		cout << "Histogram Title B: " << title_b << endl;
		cout << "Histogram Title C: " << title_c << endl;
		cout << "Histogram Title D: " << title_d << endl;
		cout << "Histogram Top Title: " << top_title << endl;
		cout << "Histogram Left Title: " << left_title << endl;
		cout << "Histogram Bottom Title: " << bottom_title << endl;
		cout << "Histogram Scale: " << scale << endl;
		cout << "Lower x-axis limit: " << lower_x_limit << endl;
		cout << "Upper x-axis limit " << upper_x_limit << endl;
		cout << "\n" << endl;
		continue;
		}
	else //Its a line that I dont care about
		{
		continue
		}
	}
return 0;
}


Many Thanks for all your help

Geoff Herbert
Line 14: inwards.open(filename.c_str()); // open() doesn't take std::string, it needs a char*

Line 63: line.erase(0, pos); Did you mean loc_0?

And you need to declare variable before using them.
Can you provide a sample of your input data? There may be an easier way to extract the information from it.
Sorry, Fraid I cant provide the file but it is basically full of things like the following:

histogram x values 50.3 and 20.3

new plot
plot size 30 20


Its effectively an input file for another programming language, and rather than change the original code that outputs the data, I'm trying to use the old data generation and search through the file using C++ for the data that I want. It should be possible. I just delete all the whitespace that I dont want and then search for specific keywords.

I don't understand the difference between a char() and a string(). I have used
inwards.open("wbbj.top") before but hoped that I could replace the filename with a string that I could input as a variable elsewhere.

And no, I meant to delete all whitespace up to the beggining of the important stuff in the line.

And where have I declared a variable before using it?

Many Thanks for all your help

Geoff
Sorry, that was supposed to be:
1
2
3
4
    histogram x values 50.3 and 20.3

         new plot
    plot size 30 20


eg, lots of whitespace indentation that I dont want to look at
If your input file has one command per line? Then you could line-process it like this:

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

#include <sstream>

// ...

while(getline(inwards, line))
{
    std::istringstream iss(line); // make an input stream from your line

    std::string command;
    iss >> command; // read first word from line (skipping whitespace)

    if(command == "histogram")
    {
        // read successive words 
        std::string word;
        iss >> word; // get first word (skipping whitespace)
        iss >> word; // get second word (skipping whitespace)
    }
    else if(command == "plot")
    {
        // read successive words 
        std::string word;
        iss >> word; // get first word (skipping whitespace)
        iss >> word; // get second word (skipping whitespace)
    }

    // every time you use iss >> stringvar; then stringvar will contain
    // the next word skipping whitespace


However that may or may not leand itself to your purpose. But turning the line that you read into an input stream using std::istringstream is a good technique for parsing a string.
Last edited on
Hi Galik, Thanks for the tips. I'd still quite like to get this code working though.

Currently its the same as above but with the string converted to a char:
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <fstream>
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{

const string ws = " \t"; //going to be used to test input

string filename = "wbbj.top"; //will need to obtain this from elsewhere eventually
char filenamechar = filename.c_str();
ifstream inwards; //initialise the opening if the file
inwards.open(filenamechar);
if( !inwards.good() ) //test to see if the file can be opened
	{
	cerr << "Cannot open the file: \"" << filename+"\"!" << endl;
	abort(); //if it can't then print an error and abort
	}

//initialise the variables
string line("");
string title_a("");
string title_b("");
string title_c("");
string title_d("");
string left_title("");
string top_title("");
string bottom_title("");
string lower_x_limit("");
string upper_x_limit("");
string scale("");
int new_plot_switch = 0;
int loc_0;
int loc_1;
int loc_2;
int loc_3;
int loc_4;
int loc_5;
int loc_6;
int loc_7;
int loc_8;
int loc_9;
int loc_10;
int loc_11;
int loc_12;
int loc_13;
int title_counter = 0;


while( getline(inwards, line)) { //whilst there are still lines from the file to read
//	line=""; //initialise line to be empty
//	inwards >> line; //take the line from the file
//	cout << "line inputted: " << line << endl; //print the inputted line to the screen

	std::string::size_type loc_0 = line.find_first_not_of(ws); // find the first non whitespace element
	if(std::string::npos == loc_0) //if the line is empty then just continue
	{ 
	continue;
	}
	else //If the line has text, then erase all whitespace up to that text
	{
        line.erase(0, pos);
	}

	// Find the location of all the important strings if they're there
	loc_1 = line.find( "SCALE", 0 );
	loc_2 = line.find( "TITLE", 0 );
	loc_3 = line.find( "SET LIMITS", 0);
	loc_4 = line.find( "title", 0);
	loc_5 = line.find( "BEGIN HIST", 0);
	loc_6 = line.find( "END HIST", 0);
	loc_7 = line.find( "NEW PLOT", 0);	
	
	//test to see if anything interesting has been found
	if (std::string::npos != loc_1) //If the line contains the y-axis scale
		{
		scale = line.substr(12); //extract just the scale used
		continue; //Once this line has been identified then we can move on with the next line 
		}
	else if (std::string::npos != loc_2) //If the line contains one of the TITLES
		{
		loc_8 = line.find( "TOP", 0); //find the location of all the relevant strings
		loc_9 = line.find( "BOTTOM", 0);
		loc_10 = line.find( "LEFT", 0);
		loc_11 = line.find( "SET TITLE", 0);
		if (std::string::npos != loc_8) //If the line contains the TITLE TOP
			{
			top_title = line.substr(10);
			continue;
			}
		else if (std::string::npos != loc_9) //If the line contains the TITLE BOTTOM
			{
			bottom_title = line.substr(13);
			continue;
			}
		else if (std::string::npos != loc_9) //If the line contains the TITLE LEFT
			{
			left_title = line.substr(11);
			continue;
			}
		else if (std::string::npos != loc_11) //If the title doesnt contain anything interesting
			{
			continue;
			}
		else 
			{
			tile_counter++;
			if (title_counter == 1)				
				{				
				title_a = line.substr(14);
				continue;
				}
			else if (tile_counter = 2)
				{
				title_b = line.substr(14);
				continue;
				}
			else
				{
				title_c = line.substr(14);
				continue;
				}
			}
		}
	else if (std::string::npos != loc_3)//If the line contains the limits of the x-axis
		{
		limits = line.substr(16);
		loc_12 = limits.find_last_of(ws);
		loc_13 = limits.find_first_of(ws);
		lower_x_limit = limits.erase(loc_13, limits.end())
		upper_x_limit = limits.erase(0, loc_12+1)
		continue;
		}
	else if (std::string::npos != loc_4) //If the line contains the title
		{
		title_d = line.substr(23);
		continue;
		}
	else if (std::string::npos != loc_5) //If the line contains the BEGIN HIST marker
		{
		begin_hist++;
		continue;
		}
	else if (std::string::npos != loc_6) //If the line contains the END HIST marker
		{
		end_hist++;
		continue;
		}
	else if (std::string::npos != loc_7) //If the line contains the NEW PLOT marker
		{
		new_plot_switch = 1;
		cout << "Histogram Title A: " << title_a << endl;
		cout << "Histogram Title B: " << title_b << endl;
		cout << "Histogram Title C: " << title_c << endl;
		cout << "Histogram Title D: " << title_d << endl;
		cout << "Histogram Top Title: " << top_title << endl;
		cout << "Histogram Left Title: " << left_title << endl;
		cout << "Histogram Bottom Title: " << bottom_title << endl;
		cout << "Histogram Scale: " << scale << endl;
		cout << "Lower x-axis limit: " << lower_x_limit << endl;
		cout << "Upper x-axis limit " << upper_x_limit << endl;
		cout << "\n" << endl;
		continue;
		}
	else //Its a line that I dont care about
		{
		continue
		}
	}
return 0;
}


But the code now returns the errors:

histogram1.cpp: In function ‘int main()’:
histogram1.cpp:13: error: invalid conversion from ‘const char*’ to ‘char’
histogram1.cpp:15: error: invalid conversion from ‘char’ to ‘const char*’
histogram1.cpp:15: error:   initializing argument 1 of ‘void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]’
histogram1.cpp:64: error: ‘pos’ was not declared in this scope
histogram1.cpp:109: error: ‘tile_counter’ was not declared in this scope
histogram1.cpp:129: error: ‘limits’ was not declared in this scope
histogram1.cpp:133: error: expected ‘;’ before ‘upper_x_limit’
histogram1.cpp:143: error: ‘begin_hist’ was not declared in this scope
histogram1.cpp:148: error: ‘end_hist’ was not declared in this scope
histogram1.cpp:170: error: expected ‘;’ before ‘}’ token


I really dont understand what is wrong? The string isnt a constant and hence I dont know why I'm getting that error.

Thanks for all your help.

Geoff
I made a few corrections and notes:

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <fstream>
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{

const string ws = " \t"; //going to be used to test input

string filename = "wbbj.top"; //will need to obtain this from elsewhere eventually

const char* filenamechar = filename.c_str(); // Galik: was wrong type

ifstream inwards; //initialise the opening if the file
inwards.open(filenamechar);
if( !inwards.good() ) //test to see if the file can be opened
	{
	cerr << "Cannot open the file: \"" << filename+"\"!" << endl;
	abort(); //if it can't then print an error and abort
	}

//initialise the variables
string line("");
string title_a("");
string title_b("");
string title_c("");
string title_d("");
string left_title("");
string top_title("");
string bottom_title("");
string lower_x_limit("");
string upper_x_limit("");
string scale("");
int new_plot_switch = 0;
int loc_0;
int loc_1;
int loc_2;
int loc_3;
int loc_4;
int loc_5;
int loc_6;
int loc_7;
int loc_8;
int loc_9;
int loc_10;
int loc_11;
int loc_12;
int loc_13;
int title_counter = 0;


while( getline(inwards, line)) { //whilst there are still lines from the file to read
//	line=""; //initialise line to be empty
//	inwards >> line; //take the line from the file
//	cout << "line inputted: " << line << endl; //print the inputted line to the screen

	std::string::size_type loc_0 = line.find_first_not_of(ws); // find the first non whitespace element
	if(std::string::npos == loc_0) //if the line is empty then just continue
	{
	continue;
	}
	else //If the line has text, then erase all whitespace up to that text
	{
        line.erase(0, pos); // Galik: Should this be loc_0 ?
	}

	// Find the location of all the important strings if they're there
	loc_1 = line.find( "SCALE", 0 );
	loc_2 = line.find( "TITLE", 0 );
	loc_3 = line.find( "SET LIMITS", 0);
	loc_4 = line.find( "title", 0);
	loc_5 = line.find( "BEGIN HIST", 0);
	loc_6 = line.find( "END HIST", 0);
	loc_7 = line.find( "NEW PLOT", 0);

	//test to see if anything interesting has been found
	if (std::string::npos != loc_1) //If the line contains the y-axis scale
		{
		scale = line.substr(12); //extract just the scale used
		continue; //Once this line has been identified then we can move on with the next line
		}
	else if (std::string::npos != loc_2) //If the line contains one of the TITLES
		{
		loc_8 = line.find( "TOP", 0); //find the location of all the relevant strings
		loc_9 = line.find( "BOTTOM", 0);
		loc_10 = line.find( "LEFT", 0);
		loc_11 = line.find( "SET TITLE", 0);
		if (std::string::npos != loc_8) //If the line contains the TITLE TOP
			{
			top_title = line.substr(10);
			continue;
			}
		else if (std::string::npos != loc_9) //If the line contains the TITLE BOTTOM
			{
			bottom_title = line.substr(13);
			continue;
			}
		else if (std::string::npos != loc_9) //If the line contains the TITLE LEFT
			{
			left_title = line.substr(11);
			continue;
			}
		else if (std::string::npos != loc_11) //If the title doesnt contain anything interesting
			{
			continue;
			}
		else
			{
			tile_counter++;  // Galik: need to declare this
			if (title_counter == 1)
				{
				title_a = line.substr(14);
				continue;
				}
			else if (tile_counter = 2)
				{
				title_b = line.substr(14);
				continue;
				}
			else
				{
				title_c = line.substr(14);
				continue;
				}
			}
		}
	else if (std::string::npos != loc_3)//If the line contains the limits of the x-axis
		{
		limits = line.substr(16);  // Galik: need to declare this
		loc_12 = limits.find_last_of(ws);
		loc_13 = limits.find_first_of(ws);
		lower_x_limit = limits.erase(loc_13, limits.end()); // Galik: missing ;
		upper_x_limit = limits.erase(0, loc_12+1); // Galik: missing ;
		continue;
		}
	else if (std::string::npos != loc_4) //If the line contains the title
		{
		title_d = line.substr(23);
		continue;
		}
	else if (std::string::npos != loc_5) //If the line contains the BEGIN HIST marker
		{
		begin_hist++; // Galik: need to declare this
		continue;
		}
	else if (std::string::npos != loc_6) //If the line contains the END HIST marker
		{
		end_hist++; // Galik: need to declare this
		continue;
		}
	else if (std::string::npos != loc_7) //If the line contains the NEW PLOT marker
		{
		new_plot_switch = 1;
		cout << "Histogram Title A: " << title_a << endl;
		cout << "Histogram Title B: " << title_b << endl;
		cout << "Histogram Title C: " << title_c << endl;
		cout << "Histogram Title D: " << title_d << endl;
		cout << "Histogram Top Title: " << top_title << endl;
		cout << "Histogram Left Title: " << left_title << endl;
		cout << "Histogram Bottom Title: " << bottom_title << endl;
		cout << "Histogram Scale: " << scale << endl;
		cout << "Lower x-axis limit: " << lower_x_limit << endl;
		cout << "Upper x-axis limit " << upper_x_limit << endl;
		cout << "\n" << endl;
		continue;
		}
	else //Its a line that I dont care about
		{
		continue; // Galik: missing ;
		}
	}
return 0;
}
Hi Galik,

Thank you so much for all your help. Managed to get it working through your help.

For anyone else who will ever read this thread, the working code is below:
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <fstream>
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{

const string ws = " \t"; //going to be used to test input

string filename = "wbbj.top"; //will need to obtain this from elsewhere eventually
const char* filenamechar = filename.c_str();
ifstream inwards; //initialise the opening if the file
inwards.open(filenamechar);
if( !inwards.good() ) //test to see if the file can be opened
	{
	cerr << "Cannot open the file: \"" << filename+"\"!" << endl;
	abort(); //if it can't then print an error and abort
	}

//initialise the variables
string line("");
string title_a("");
string title_b("");
string title_c("");
string title_d("");
string left_title("");
string top_title("");
string bottom_title("");
string lower_x_limit("");
string upper_x_limit("");
string scale("");
string limits("");
int new_plot_switch = 0;
int loc_0;
int loc_1;
int loc_2;
int loc_3;
int loc_4;
int loc_5;
int loc_6;
int loc_7;
int loc_8;
int loc_9;
int loc_10;
int loc_11;
int loc_12;
int loc_13;
int title_counter = 0;
int begin_hist = 0;
int end_hist = 0;


while( getline(inwards, line)) { //whilst there are still lines from the file to read
//	line=""; //initialise line to be empty
//	inwards >> line; //take the line from the file
//	cout << "line inputted: " << line << endl; //print the inputted line to the screen

	std::string::size_type loc_0 = line.find_first_not_of(ws); // find the first non whitespace element
	if(std::string::npos == loc_0) //if the line is empty then just continue
	{ 
	continue;
	}
	else //If the line has text, then erase all whitespace up to that text
	{
        line.erase(0, loc_0);
	}


	// Find the location of all the important strings if they're there
	loc_1 = line.find( "SCALE", 0 );
	loc_2 = line.find( "TITLE", 0 );
	loc_3 = line.find( "SET LIMITS", 0);
	loc_4 = line.find( "title", 0);
	loc_5 = line.find( "BEGIN HIST", 0);
	loc_6 = line.find( "END HIST", 0);
	loc_7 = line.find( "NEW PLOT", 0);	
	
	//test to see if anything interesting has been found
	if (std::string::npos != loc_1) //If the line contains the y-axis scale
		{
		scale = line.substr(12); //extract just the scale used
		continue; //Once this line has been identified then we can move on with the next line 
		}
	else if (std::string::npos != loc_2) //If the line contains one of the TITLES
		{
		loc_8 = line.find( "TOP", 0); //find the location of all the relevant strings
		loc_9 = line.find( "BOTTOM", 0);
		loc_10 = line.find( "LEFT", 0);
		loc_11 = line.find( "SET TITLE", 0);
		if (std::string::npos != loc_8) //If the line contains the TITLE TOP
			{
			top_title = line.substr(10);
			continue;
			}
		else if (std::string::npos != loc_9) //If the line contains the TITLE BOTTOM
			{
			bottom_title = line.substr(13);
			continue;
			}
		else if (std::string::npos != loc_9) //If the line contains the TITLE LEFT
			{
			left_title = line.substr(11);
			continue;
			}
		else if (std::string::npos != loc_11) //If the title doesnt contain anything interesting
			{
			continue;
			}
		else 
			{
			title_counter++;
			if (title_counter == 1)				
				{				
				title_a = line.substr(14);
				continue;
				}
			else if (title_counter = 2)
				{
				title_b = line.substr(14);
				continue;
				}
			else
				{
				title_c = line.substr(14);
				continue;
				}
			}
		}
	else if (std::string::npos != loc_3)//If the line contains the limits of the x-axis
		{
		limits = line.substr(16);
		loc_12 = limits.find_last_of(ws);
		loc_13 = limits.find_first_of(ws);
        line.erase(0, loc_0);
		lower_x_limit = limits;
		lower_x_limit.erase(loc_13, lower_x_limit.length());
		upper_x_limit = limits;
		upper_x_limit.erase(0, loc_12+1);
		continue;
		}
	else if (std::string::npos != loc_4) //If the line contains the title
		{
		title_d = line.substr(23);
		continue;
		}
	else if (std::string::npos != loc_5) //If the line contains the BEGIN HIST marker
		{
		begin_hist++;
		continue;
		}
	else if (std::string::npos != loc_6) //If the line contains the END HIST marker
		{
		end_hist++;
		continue;
		}
	else if (std::string::npos != loc_7) //If the line contains the NEW PLOT marker
		{
		new_plot_switch = 1;
		cout << "Histogram Title A: " << title_a << endl;
		cout << "Histogram Title B: " << title_b << endl;
		cout << "Histogram Title C: " << title_c << endl;
		cout << "Histogram Title D: " << title_d << endl;
		cout << "Histogram Top Title: " << top_title << endl;
		cout << "Histogram Left Title: " << left_title << endl;
		cout << "Histogram Bottom Title: " << bottom_title << endl;
		cout << "Histogram Scale: " << scale << endl;
		cout << "Lower x-axis limit: " << lower_x_limit << endl;
		cout << "Upper x-axis limit " << upper_x_limit << endl;
		cout << "\n" << endl;
		continue;
		}
	else //Its a line that I dont care about
		{
		continue;
		}
	}
return 0;
}


Many Thanks again Galik,

Geoff
Topic archived. No new replies allowed.