title: Reading data from a file and Writing it to a different file (Visual studio 2012)
body: <p>The problem I have is that I'm reading data from files and then I write them to file, but the very first element gets cut out. I will show you an example. Sorry for the language, however it should not interrupt with understanding what is going on, this code is kinda simple.</p>
  
  <p>So the data files. From this:</p>
  
  <pre><code>   4 12
      Domas P 2 balta Z 0 balta R 0 balta B 0 balta V 0 balta K 0 balta P 2 juoda Z 0 juoda R 0 juoda B 0 juoda V 0 juoda K 0 juoda
      Lukas P 4 balta Z 0 balta R 0 balta B 0 balta V 0 balta K 0 balta P 4 juoda Z 0 juoda R 0 juoda B 0 juoda V 0 juoda K 0 juoda
      Tomas P 6 balta Z 0 balta R 0 balta B 0 balta V 0 balta K 0 balta P 6 juoda Z 0 juoda R 0 juoda B 0 juoda V 0 juoda K 0 juoda
      Tadas P 8 balta Z 0 balta R 0 balta B 0 balta V 0 balta K 0 balta P 8 juoda Z 0 juoda R 0 juoda B 0 juoda V 0 juoda K 0 juoda
  </code></pre>
  
  <p>I am getting this:</p>
  
  <pre><code>P      2 balta    Z      0 balta    R      0 balta    B      0 balta    V      0 balta    K      0 balta    P      2 juoda    P      4 balta    Z      0 balta    R      0 balta    B      0 balta    V      0 balta
  Lukas    P      4 balta    Z      0 balta    R      0 balta    B      0 balta    V      0 balta    K      0 balta    P      4 juoda    P      6 balta    Z      0 balta    R      0 balta    B      0 balta    V      0 balta
  Tomas    P      6 balta    Z      0 balta    R      0 balta    B      0 balta    V      0 balta    K      0 balta    P      6 juoda    P      8 balta    Z      0 balta    R      0 balta    B      0 balta    V      0 balta
  Tadas    P      8 balta    Z      0 balta    R      0 balta    B      0 balta    V      0 balta    K      0 balta    P      8 juoda    Z      0 juoda    R      0 juoda    B      0 juoda    V      0 juoda    K      0 juoda
  </code></pre>
  
  <p>The very first element "Domas" got cut out. If it would be an int type variable, it would show -884646546 or something like that. As i already know it means the program can't find anything and writes and empty space or that random negative stuff. However I don't know how to fix this, which is the problem. Thanks for any help!</p>
  
  <pre><code>#include &lt;iomanip&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;istream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  const char CD1fv[] = "Komplektai.txt";
  const char CD2fv[] = "Parama.txt";
  const char CRfv[] = "Turnyras.txt";
  
  class Komplektas
  {
  private:
      int eile;
      int kiek;
      string fig;
      string spalva;
      string vardas;
  public:
      Komplektas(int k = 0, string f = "", string s = "") :
      kiek(k), fig(f), spalva(s) { }
      ~Komplektas() { }
      void Deti(int k, string f, string s) { kiek = k; fig = f, spalva = s; }
      void Eile(int e) { eile = e; }
      void Vardas(string v) { vardas = v; }
      string ImtiVarda() { return vardas; }
      int ImtiEile() { return eile; }
      string ImtiFigura() { return fig; }
      int ImtiKieki() { return kiek; }
      string ImtiSpalva() {return spalva; }
  };
  
  class Matrica
  {
  public:
      static const int CMaxEil = 100;
      static const int CMaxSt = 7;
  private:
      Komplektas A[CMaxEil][CMaxSt];
      int n;
      int m;
  public:
      Matrica(int nn = 0, int mm = 0) : n(nn), m(mm) { }
      ~Matrica() { }
      int ImtiN() { return n; }
      int ImtiM() { return m; }
      void DetiN(int nn) {n = nn; }
      void DetiM( int mm) { m = mm; }
      void DetiReiksme( int i, int j, Komplektas r) {A[i][j] = r; }
      Komplektas ImtiReiksme(int i, int j) { return A[i][j]; }
  };
  void Ivesti1(const char fv[], Matrica &amp; A);
  void Ivesti2(const char fv[], Matrica &amp; A);
  void Spausdinti1(const char fv[], Matrica &amp; A);
  void Spausdinti2(const char fv[], Matrica &amp; A);
  
  
  int main()
  {
      Matrica Figuros;
  
      Ivesti1(CD1fv, Figuros);
      Spausdinti1(CRfv, Figuros);
  
      Ivesti2(CD2fv, Figuros);
      Spausdinti2(CRfv, Figuros);
  
      cout &lt;&lt; "Pradiniai duomenys isspausdinti faile " &lt;&lt; CRfv &lt;&lt; endl;
      cout &lt;&lt; "Programa baige darba" &lt;&lt; endl;
      return 0;
  }
  
  void Ivesti1(const char fv[], Matrica &amp; A)
  {
      int n, m;
      string spalva;
      string fig;
      int eile, kiek;
      Komplektas komplektas;
      ifstream fd(fv);
      fd &gt;&gt; n &gt;&gt; m;
      A.DetiN(n);
      A.DetiM(m);
      fd.ignore();
      for (int i = 0; i &lt; n; i++){
          fd &gt;&gt; eile;
          komplektas.Eile(eile);
          for (int j = 0; j &lt; m; j++) {
              fd &gt;&gt; fig &gt;&gt; kiek &gt;&gt; spalva;
              komplektas.Deti(kiek, fig, spalva);
              A.DetiReiksme(i, j, komplektas);
          }
  
      }
  
      fd.close();
  }
  
  void Spausdinti1(const char fv[], Matrica &amp; A)
  {
      Komplektas x;
      ofstream fr(fv, ios::app);
      for (int i = 0; i &lt; A.ImtiN(); i++) {
          fr &lt;&lt; i+1;
          for (int j = 0; j &lt; A.ImtiM(); j++) {
              x = A.ImtiReiksme(i , j);
              fr &lt;&lt; setw(5) &lt;&lt; x.ImtiFigura() &lt;&lt; " " &lt;&lt; right
                  &lt;&lt; setw(6) &lt;&lt; x.ImtiKieki() &lt;&lt; " " &lt;&lt; x.ImtiSpalva();
          }
          fr &lt;&lt; endl;
      }
      fr &lt;&lt; endl;
      fr.close();
  }
  
  void Ivesti2(const char fv[], Matrica &amp; A)
  {
      int n, m;
      string spalva;
      string fig;
      string vardas;
      int eile, kiek;
      Komplektas komplektas;
      ifstream fd(fv);
      fd &gt;&gt; n &gt;&gt; m;
      A.DetiN(n);
      A.DetiM(m);
      fd.ignore();
      for (int i = 0; i &lt; n; i++){
          fd &gt;&gt; vardas;
          komplektas.Vardas(vardas);
          for (int j = 0; j &lt; m; j++){
              fd &gt;&gt; fig &gt;&gt; kiek &gt;&gt; spalva;
              komplektas.Deti(kiek, fig, spalva);
              A.DetiReiksme(i, j, komplektas);
          }
      }
      fd.close();
  }
  
  void Spausdinti2(const char fv[], Matrica &amp; A)
  {
      Komplektas x;
      ofstream fr(fv, ios::app);
      for (int i = 0; i &lt; A.ImtiN(); i++) {
          fr &lt;&lt; x.ImtiVarda();
          for (int j = 0; j &lt; A.ImtiM(); j++) {
              x = A.ImtiReiksme(i , j);
              fr &lt;&lt; setw(5) &lt;&lt; x.ImtiFigura() &lt;&lt; " " &lt;&lt; right
                  &lt;&lt; setw(6) &lt;&lt; x.ImtiKieki() &lt;&lt; " " &lt;&lt; x.ImtiSpalva();
          }
          fr &lt;&lt; endl;
      }
      fr &lt;&lt; endl;
      fr.close();
  }
  </code></pre>