Better importation of variables from .txt file I am an artist and a total beginner in C++.

I would like to find a better method of importing my variables from a values.txt file, which may contain 18 values in one column:

63.64474122
5.214728341
0.405110193
0.261556475
-2.00743E-09
2.76001E-10
34.45902482
15.62249852
0.220861685
2.88127E-09
0.445804979
2.76001E-10
82.11020306
14.02709406
0.507487944
2.88127E-09
-2.00743E-09
0.159178722


… or it could contain three rows of six tab-separated columns:

63.64474122 5.214728341 0.405110193 0.261556475 -2.00743E-09    2.76001E-10
34.45902482 15.62249852 0.220861685 2.88127E-09 0.445804979 2.76001E-10
82.11020306 14.02709406 0.507487944 2.88127E-09 -2.00743E-09    0.159178722


I know my code is ugly.  Could somebody help?

#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;algorithm&gt;
using namespace std;

#define PI 3.14159265

//___________________________________________________

/// variables from the *.txt file 

double x_A = 0;
double y_A = 0;
double d_A = 0;
double m_A = 0;
double c_A = 0;
double t_A = 0;
double x_B = 0;
double y_B = 0;
double d_B = 0;
double m_B = 0;
double c_B = 0;
double t_B = 0;
double x_C = 0;
double y_C = 0;
double d_C = 0;
double m_C = 0;
double c_C = 0;
double t_C = 0;

//__________________________________________________

int trash    = 0;   

//___________________________________

int main() {

    ifstream ifs ("values.txt"); ///LOADING
    if (!ifs)
    // process error
    ifs &gt;&gt; trash;
    ifs &gt;&gt; x_A;
    ifs &gt;&gt; y_A;
    ifs &gt;&gt; d_A;
    ifs &gt;&gt; m_A;
    ifs &gt;&gt; c_A;
    ifs &gt;&gt; t_A;
    ifs &gt;&gt; x_B;
    ifs &gt;&gt; y_B;
    ifs &gt;&gt; d_B;
    ifs &gt;&gt; m_B;
    ifs &gt;&gt; c_B;
    ifs &gt;&gt; t_B;
    ifs &gt;&gt; x_C;
    ifs &gt;&gt; y_C;
    ifs &gt;&gt; d_C;
    ifs &gt;&gt; m_C;
    ifs &gt;&gt; c_C;
    ifs &gt;&gt; t_C;

cout &lt;&lt; x_A &lt;&lt; endl;
cout &lt;&lt; y_A &lt;&lt; endl;
cout &lt;&lt; d_A &lt;&lt; endl;
cout &lt;&lt; m_A &lt;&lt; endl;
cout &lt;&lt; c_A &lt;&lt; endl;
cout &lt;&lt; t_A &lt;&lt; endl;
cout &lt;&lt; x_B &lt;&lt; endl;
cout &lt;&lt; y_B &lt;&lt; endl;
cout &lt;&lt; d_B &lt;&lt; endl;
cout &lt;&lt; m_B &lt;&lt; endl;
cout &lt;&lt; c_B &lt;&lt; endl;
cout &lt;&lt; t_B &lt;&lt; endl;
cout &lt;&lt; x_C &lt;&lt; endl;
cout &lt;&lt; y_C &lt;&lt; endl;
cout &lt;&lt; d_C &lt;&lt; endl;
cout &lt;&lt; m_C &lt;&lt; endl;
cout &lt;&lt; c_C &lt;&lt; endl;
cout &lt;&lt; t_C &lt;&lt; endl;

}
Storing the data in 18 independent variables is awkward.  The naming of your variables suggests that each group of six doubles represents an object, which I've called a Sexdoublet.

Throwing all the code into main() is poor practice; there should be a function to do the importing.  It should accept an istream parameter and return a vector of Sexdoublets.

I don't know what you were hoping to accomplish with if (!ifs) ifs &gt;&gt; trash; — if the ifstream is bad then you shouldn't try reading from it.

Hard-coding the filename is probably a bad idea.  I've used the convention of reading from either a file that is specified on the command line, or from standard input otherwise.

#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;string.h&gt;
#include &lt;vector&gt;

/* A struct of six doubles */
struct Sexdoublet {
    double x, y, d, m, c, t;

    friend std::istream &amp;operator&gt;&gt;(std::istream &amp;in, Sexdoublet &amp;r) {
        return in &gt;&gt; r.x &gt;&gt; r.y &gt;&gt; r.d &gt;&gt; r.m &gt;&gt; r.c &gt;&gt; r.t;
    }

    friend std::ostream &amp;operator&lt;&lt;(std::ostream &amp;out, const Sexdoublet &amp;r) {
        return out &lt;&lt; "[ x = " &lt;&lt; r.x
                   &lt;&lt; ", y = " &lt;&lt; r.y
                   &lt;&lt; ", d = " &lt;&lt; r.d
                   &lt;&lt; ", m = " &lt;&lt; r.m
                   &lt;&lt; ", c = " &lt;&lt; r.c
                   &lt;&lt; ", t = " &lt;&lt; r.t &lt;&lt; " ]";
    }
};

std::vector&lt;Sexdoublet&gt; import(std::istream &amp;in) {
    std::vector&lt;Sexdoublet&gt; data;
    Sexdoublet s;
    while (in &gt;&gt; s) {
        data.push_back(s);
    }
    return data;
}

int main(int argc, char *argv[]) {
    // If the first command-line argument is not "-", treat it as the filename
    // from which to read the input.  Otherwise, read from STDIN.
    const char *filename = (argc &gt;= 2 &amp;&amp; 0 != strcmp("-", argv[1])) ?
                                argv[1] : NULL;
    std::ifstream f;
    std::istream &amp;in = filename ? (f.open(filename), f) : std::cin;
    if (!f) {
        std::cerr &lt;&lt; "Error opening " &lt;&lt; filename &lt;&lt; ": "
                  &lt;&lt; strerror(errno) &lt;&lt; std::endl;
        return 1;
    }

    std::vector&lt;Sexdoublet&gt; data = import(in);
    std::for_each(data.begin(), data.end(), [](const Sexdoublet &amp;s) {
        std::cout &lt;&lt; s &lt;&lt; std::endl;
    });
    return 0;
}