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)
#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
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?