I cannot initiate an integer vector in C++ -
i have following code excerpt.
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <fstream> #include <string> #include <array> using namespace std; int solver(int t) { /* read ia */ ifstream inputfile("ia [0;1.3077].txt"); vector<int> ia; if (inputfile) { int num; while ( inputfile >> num) { ia.push_back(num); } } } int main (void) { solver(360); }
but gives me error:
error: implicit instantiation of undefined template 'std::__1::vector<int, std::__1::allocator<int> >' vector<int> ia; ^ /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:200:29: note: template declared here class _libcpp_type_vis_only vector;
the goal read txt file integers per line without knowing how many lines there in advance. i'm choosing vector hold data because don't want initialize integer array fixed size. have suggestions?
also, understand variable t
unused - use after .txt file loaded.
you need to:
#include <vector>
you must alway include directly headers types use.
Comments
Post a Comment