Partially Fill an array from a file

后端 未结 1 1014
既然无缘
既然无缘 2021-01-24 23:26

I need to partially fill 2 arrays with data from a file and keep them parallel. But my current code gives me errors that look like giberish. If someone could even just help me d

1条回答
  •  深忆病人
    2021-01-24 23:59

    istream::operator>> has overloads for neither arrays of strings nor arrays of integers.
    

    You'll have to read each string and each integer in one at a time. Originally posted by @Seth Carnegie

    input (infile, names, numoftoys); //your call was completely wrong
    
    infile.ignore ('\n'); //notice the char instead of string
    
    infile >> names >> numoftoys; //this won't work like this but at least we fixed the declaration error
    

    If you are allowed to use std::vector, etc. We could provide a more C++ answer. Also please avoid using - using namespace std;

    0 讨论(0)
提交回复
热议问题