title: C++ File-stream Vector Input
body: <p>I am currently working in c++. My goal is to be able to implement the A* algorithm, through a series of steps I plan to be able to store, and list the shortest path from Point A to Point B. </p>
  
  <p>My program will take in a command-line argument which will be a file to read in. The purpose of giving the program a file t read in is that each file is its own "grid" for A* to process. The format for the grid file is as follows:</p>
  
  <p>Num 1 = WIDTH and then Num 2 = HEIGHT</p>
  
  <p>o = start</p>
  
  <p>* = finish</p>
  
  <p>. = passable node</p>
  
  <p># = impassable wall</p>
  
  <p>So an example grid, let's call it "Grid1", would be:</p>
  
  <pre><code>8 5 
  o......#
  ......##
  .....###
  ....####
  .......*
  </code></pre>
  
  <p>So to process this, when you run the program you would pass in "Grid1".
  From here, I plan to create a filestream and read in each character into a 2D Array/Vector to attempt to recreate the grid so I can have positions. For example, in "Grid1" the character "o" would be at position [0][0] in a Array/Vector. My attempted implementation is as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  #include &lt;unordered_map&gt;
  
  using namespace std;
  
  int main(int argc, char *argv[]) 
  {
      //Checking for CLA
      if( argc &lt; 1 ) 
      {   
      cout &lt;&lt; "Program must take atleast &lt;1&gt; arguments!" &lt;&lt; endl &lt;&lt; "1) File to read  2) OPTIONAL: Type of search" &lt;&lt; endl;
  }   
  
  //CLA #1 is the file containing GRID to be read in
  string gridTBO = argv[1];
  
  //Start new filestream and open grid file for reading
  ofstream gridFile;
  gridFile.open( gridTBO );  
  
  //Check to make sure we can even open the file before proceeding
  if( gridFile.is_open() )
  {   
  //To store grid data
  vector&lt;string&gt; grid;
  grid[0][0].push_back("Hello");
  cout &lt;&lt; grid[0][0]; 
  
  }   
  </code></pre>
  
  <p>However, in regards to my "push_back", it seems that I am not able to print out or throw the data into the vector. I would primarily want each index such as [0][0] [0][1] [0][2] to hold each individual character in order to recreate a grid like the one I pass in. </p>
  
  <p>I am not quite sure what I am doing incorrectly as I am fairly inexperienced using vectors, however, the code for pushing data into the grid is purely for testing purposes. Once I am able to parse some data into the vector, I would then like to automate it with a loop and have "getline" or a similar function grab the data for me.</p>
  
  <p>So my main questions are:
  1) Why is my push_back and print out failing?
  2) How would I read in char by char with a loop to prevent me from manually putting data in?</p>
  
  <p>The error I receive on run-time is:
  <strong>Segmentation Fault(core dump)</strong></p>
  
  <p>Thank you everyone in advance for your assistance and knowledge!</p>