I have this program:
#include <iostream>
#include <vector>
#include <math.h>
#include <cstdlib>
#include <iomanip>
#include <sstream>
using namespace std;
void ProvaErrore() {
string line, line1;
char delim = ' ';
ifstream myfile("DatiMemoria.txt");
int i = 0, j = 0;
vector<vector<double>> vettore(40);
vector<double> risultato;
while (getline(myfile, line1))
{
stringstream ss(line1);
while (getline(ss, line, delim))
{
if (j == 12)
{
i++;
j = 0;
}
if (j == 0)
{
if (line == 'p')
{
risultato.push_back(0);
}
else
{
risultato.push_back(1);
}
}
if (j == 1)
{
if (line == 'x')
{
vettore[i].push_back(0);
}
else
{
vettore[i].push_back(1);
}
}
if (j == 2)
{
if (line == 's')
{
vettore[i].push_back(0);
vettore[i].push_back(0);
}
if (line == 'y')
{
vettore[i].push_back(0);
vettore[i].push_back(1);
}
if (line == 'f')
{
vettore[i].push_back(1);
vettore[i].push_back(0);
}
}
if (j == 3)
{
if (line == 'w')
{
vettore[i].push_back(0);
}
if (line == 'n')
{
vettore[i].push_back(1);
}
}
if (j == 4)
{
if (line == 't')
{
vettore[i].push_back(0);
}
if (line == 'f')
{
vettore[i].push_back(1);
}
}
if (j == 5)
{
if (line == 'l')
{
vettore[i].push_back(0);
vettore[i].push_back(0);
}
if (line == 'p')
{
vettore[i].push_back(0);
vettore[i].push_back(1);
}
if (line == 'n')
{
vettore[i].push_back(1);
vettore[i].push_back(0);
}
if (line == 'a')
{
vettore[i].push_back(1);
vettore[i].push_back(1);
}
}
if (j == 6)
{
if (line == 'b')
{
vettore[i].push_back(0);
}
if (line == 'n')
{
vettore[i].push_back(1);
}
}
if (j == 7)
{
if (line == 'k')
{
vettore[i].push_back(0);
vettore[i].push_back(0);
}
if (line == 'w')
{
vettore[i].push_back(0);
vettore[i].push_back(1);
}
if (line == 'n')
{
vettore[i].push_back(1);
vettore[i].push_back(0);
}
if (line == 'p')
{
vettore[i].push_back(1);
vettore[i].push_back(1);
}
}
if (j == 8)
{
if (line == 'c')
{
vettore[i].push_back(0);
}
if (line == 'e')
{
vettore[i].push_back(1);
}
}
if (j == 9)
{
if (line == 'k')
{
vettore[i].push_back(0);
}
if (line == 'n')
{
vettore[i].push_back(1);
}
}
if (j == 10)
{
if (line == 's')
{
vettore[i].push_back(0);
}
if (line == 'v')
{
vettore[i].push_back(1);
}
}
if (j == 11)
{
if (line == 'g')
{
vettore[i].push_back(0);
}
if (line == 'u')
{
vettore[i].push_back(1);
}
}
j++;
}
}
for (int i = 0; i < 40; i++)
{
for (int j = 0; j < 14; j++)
{
cout << vettore[i][j]<<" ";
}
cout << "\n";
}
}
With that txt file:
e x y w t a b n c n s g
p x s w t p n k e k s g
p x y n t p n k e n v u
p x y w t p n w e k s g
p x s w t p n n e n s g
p x y w t p n w e n s g
p x y w t p n k e n s g
p x y w t p n k e k s g
p x y n t p n p e k v u
e f f n f n n p e n v u
p f y n t p n k e k v u
p x s w t p n w e n s g
p f y n t p n k c n v u
p x y n t p n n e n v u
p x s w t p n k e n s g
p f s n t p n p e k v u
p x y n t p n p e n v u
p x y w t p n n e k s g
p x y n t p n k e k v u
e x f n f n n n e k v u
e x s w t l b k c k s g
e x f n f n n k e n v u
e x y w t l b w c k s g
p f y n t p n p e n v u
e x s w t l b n c n s g
e x y w t a b w c n s g
e x y w t a b k c n s g
e x y w t l b k c k s g
e x f n f n n p e k v u
p x y n t p n n e k v u
e f f n f n n k e k v u
e x s w t l b w c n s g
e f f n f n n k e n v u
e x f n f n n n e n v u
e x s w t a b k c n s g
e f f n f n n p e k v u
e x f n f n n p e n v u
e x y w t l b n c k s g
e x f n f n n k e k v u
p x y w t p n n e n s g
It is a simple program useful for data analysis. I have a file with 40 lines. Each line is a mushroom and each column is a feature for example the first one is edible or poisonus. I want to read that file and transform the letter in numbers (in bynary numbers) in order to put them in a neural network. Normally I do this with python but I wanted to try in c++
When I first run it everything is fine. But if I try to rerun it I have this error:
error: no matching constructor for initialization of 'std::stringstream' (aka 'basic_stringstream<char, char_traits<char>,
allocator<char> >')
stringstream ss(line1);
^ ~~~~~
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\include\sstream:531:14: note: candidate constructor not viable: no known conversion from 'std::string' (aka 'basic_string<char, char_traits<char>,
allocator<char> >') to 'ios_base::openmode' (aka 'int') for 1st argument
explicit basic_stringstream(ios_base::openmode _Mode = ios_base::in | ios_base::out)
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\include\sstream:539:5: note: candidate constructor not viable: no known conversion from 'std::string' (aka 'basic_string<char, char_traits<char>,
allocator<char> >') to 'std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' for 1st
argument
basic_stringstream(basic_stringstream&& _Right) : _Mybase(&_Stringbuffer) { // construct by moving _Right
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\include\sstream:562:5: note: candidate constructor not viable: no known conversion from 'std::string' (aka 'basic_string<char, char_traits<char>,
allocator<char> >') to 'const std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' for
1st argument
basic_stringstream(const basic_stringstream&) = delete;
Why?