I am having trouble with adding ints form a file to a set container. Could someone provide a short example or point me to a tutorial somewhere. I searched all over google and could not find anything helpful.
Thanks
I am having trouble with adding ints form a file to a set container. Could someone provide a short example or point me to a tutorial somewhere. I searched all over google and could not find anything helpful.
Thanks
How about posting the code you are having issues with?
That helps avoid playing 20 questions.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Here is what I have so far
Code:#include <iostream> #include <stdlib.h> #include <vector> #include <fstream> #include <string> #include <set> using namespace std; class Numbers { public: void add ( int x_p ) ; // add item to set Set () ; // creates empty set private: vector <int> intigers ; }; int main() { Numbers num; ifstream in_data; in_data.open ("D:\\numbers.txt"); if ( ! in_data) { cout << "File not opened" << endl; exit (1); } cout << "How many ints do you want to add ?" << endl; int z; cin >> z; for (int i = 0 ; i < z ; i++) { cout << "Enter an int" << endl; int x ; cin >> x; num.add (x) ; } system("PAUSE"); return 0; } void Numbers::add (int x_p) { }
My first issue is a typo:The language is case-sensitive; got something that compiles for me?Code:Set () ; // creates empty set
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Your class has a vector, but you said you want a set. Just change vector to set. Then, use the insert function from the set class.