problems with writing to a file

Ok guys i am currently on a mini endeavour to get some things straight again in my head regarding c++ programming, and i have made a very simple program to write to an xml file (yes, i know xerxes in case someone will suggest this) and here is the error IDE: Eclipse Helios:
1
2
3
4
5
Description	                 Resource	
fstream’ has not been declared	 main.cpp	

Path                          Location     Type
/Reading_an_XML_simple/src    line 29      C/C++ Problem


and here is the code in case someone wants to check it out:
(note that i haven't started tweaking it since i have not been able to make it work)

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
#include <iostream>
#include <fstream>
#include <string>
#include <ios>
class opener {
private:
	//making an fopen object called data
	std::fstream data;

	/*Or instead of std::string a declaration of using std::string can be made and just deploy string normally*/

	//problem text, solution text, operational categorizations, and problem_title -> the block title
	std::string problem_title, problem, solution, op_tier1, op_tier2, op_tier3;

	//we need the path to the friggin' file don't we now...
	std::string path;

	//product categorizations
	std::string p_tier1, p_tier2, p_tier3;

	void pumpData () {
		data.open(path, fstream::out | fstream::app); //get the path, pump data out and append it to the EOF
		data << "<" << problem_title << ">" << std::endl;
		data << "<problem>" << problem << "</problem>" << std::endl;
		data << "<solution>" << solution << "</solution>" << std::endl;
		data << "<op_categorization>" << std::endl;
		data << "<op_tier_1>" << op_tier1 << "</op_tier_1>" << std::endl;
		data << "<op_tier_2>" << op_tier2 << "</op_tier_2>" << std::endl;
		data << "<op_tier_3>" << op_tier3 << "</op_tier_3>" << std::endl;
		data << "</op_categorization>" << std::endl;
		data << "<p_categorization>" << std::endl;
		data << "<p_tier_1>" << p_tier1 << "</p_tier_1>" << std::endl;
		data << "<p_tier_2>" << p_tier2 << "</p_tier_2>" << std::endl;
		data << "<p_tier_3>" << p_tier3 <<  "</p_tier_3>" << std::endl;
		data << "</p_categorization>" << std::endl;
		data << "</" << problem_title << ">" << std::endl;

		data.close(); //close the name of the file
	} //end of pumpData


public:
	void getData () {
		std::cout << "Please enter the path of the file:" << std::endl;
		std::cin >> path ;

		//checking for blank path and prompting the to enter one
		while (path=="") {
			std::cout << "Please enter a path:" << std::endl;
			std::cin >> path;
		} //end of the while checker

		std::cout << "Please enter the solution of the text:" << std::endl;
		std::cin >> problem;

		std::cout << "Please enter the first operational tier:" << std::endl;
		std::cin >> op_tier1;

		std::cout << "Please the second operational tier:" << std::endl;
		std::cin >> op_tier2;

		std::cout << "Please enter the third operational tier" << std::endl;
		std::cin >> op_tier3;

		std::cout << "Please enter the first product categorization tier:" << std::endl;
		std::cin >> p_tier1;

		std::cout << "Please enter the second product categorization tier:" << std::endl;
		std::cin >> p_tier2;

		std::cout << "Please enter the third product categorization tier:" << std::endl;
		std::cin >> p_tier3;

		pumpData();
	} //end of getData
};

int main() {
	opener Opener;
	Opener.getData();
	return 0;
}


I tried o change the path of the libraries in Eclipse, and nothing, so i don't know what i am doing wrong
Last edited on
Ok i am a noob, at line 22 i forgot that fstream needs an std, so instead of:

data.open(path, fstream::out | fstream::app); //get the path, pump data out and append it to the EOF

i changed to:

data.open(path, std::fstream::out | std::fstream::app); //get the path, pump data out and append it to the EOF

but now i get:

Description Resource Path Location Type
no matching function for call to std::basic_fstream<char>::open(std::string&, std::_Ios_Openmode)

so in case any ideas are available I'd be happy,

thnx in advance
Ok i have found the problem, since the string type is not exactly something that is handled well by the open function of the fstream class, i have inclided path.c_str() to actually make it work and now everything happens well just that i no information appears on the file actually.

so since that is said and done, i think i have done everything necessary...
mainly:

i have opened the file and also told that i will output stuff and told that this outpus should be appended to the file, ok that is said and done...
i gave a path, and yes i included a check for spaces, since i use linux and have no spaces for these foldrs / file names, and just to check if i make a typo...

i have declares a bunch of strings and then stored the stuff needed for that and then called the private writing function, so mainly first actually what happens is that the data is stored in strings, and after that the file is opened and the input should be passed to the data object and thus to the file, am i saying something wrong?

Thanks in advance
Topic archived. No new replies allowed.