c++ - Why do I keep getting a segmentation fault when passing objects by reference? -


I am trying to get data from a file and store it in the object that I have created I have a partition I am walking in the wrong way, but I am not sure what is the reason for this. Here's the code:

  object < String & gt; PopulateObj (& lt; string & gt; & quot; of the object); String string (string); Int main () {string stringFile; Ifstream Infographic; Offream outfile; & Lt; String & gt; Obj1; Cout & lt; & Lt; "Enter the name of the dictionary file" & lt; & Lt; Endl; Cin & gt; & Gt; DictionaryFile; Obj1 = populateObj (obj1, dictionary file); } Object & lt; String & gt; PopulateObj (object & lt; string & gt; and oz, string filename) {ifstream file; String word = ""; File.open (file name); If (file.is_open ()) {while (! File.eof ()) {file & gt; & Gt; word; Obj.add (word); }} And cout & lt; & Lt; "Could not open file ..." & lt; & Lt; Endl; Return obj; }  

This may or may cause problems, but this is incorrect :

  if (file.is_open ()) {while (! File.eof ()) {file & gt; & Gt; word; Obj.add (word); }}  

Try instead:

  while (file & gt; & gt; word) {obj.add (word); }  

The use of your original code EOF can be very useful.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -