I can not read a txt file correctly and transfer it to a map in c ++.
The code I've developed works only if it has no "" spaces in the txt, if it has looped and does not work. Here is the code:
void dados::pesquisarProdutos(){
arq.open("produtos.txt",ios::in);
if (arq.fail()){
perror("erro ao pesquisar: ");
sleep(1);
return;
}
string nome;
float preco;
int qnt;
while (!arq.eof()){
arq >> nome >> preco >> qnt;
map1.insert(make_pair(nome,loja(nome,preco,qnt)));
}
cout << "Qual produto procura: ";
getline(cin,nome);
it = map1.find(nome);
cout << it->first << "preco: "<< it->second.getPreco() << "quantidade: "<<
it->second.getEstoque();
arq.close();}
If the product name is, for example, rice, it saves on the map and works normal, now if it is white rice, of the error. By the way the problem is in reading space, but I do not know how to solve.
Thanks for the help