Cout string c++

Asked

Viewed 400 times

1

I have a function Show() which traverses a list and should display it on the screen, but I cannot concatenate the value of a list with a string. Follows code:

#include "pch.h"
#include <iostream>
#include <string>
#define MAX 5
typedef struct {
    string Nome;
    double Salario;
} Funcionario;

typedef struct {
    Funcionario Funcionarios[MAX];
    int Inicio, Fim;
} Lista;


void Show(Lista *Lista) {
    for (int i = 0; i < Lista->Fim; i++) {
        cout << "Func.: " << Lista->Funcionarios[i].Nome;
        cout << "Salário: " << Lista->Funcionarios[i].Salario;
    }
}

The problem is in

 cout << "Func.: " << Lista->Funcionarios[i].Nome;

where I can’t do the cout. I have the following mistake

E0349 no "<<" operator corresponds to these operands the types of operands are: Std::basic_ostream> << Std::string

  • 1

    Made the call using namespace std;? In case I didn’t, yours cout must be std::cout.

  • Yes I had already done.

1 answer

2

The problem was importing one of the libraries.

I traded

#include <string.h>

for

#include <string>
  • 1

    includes . h are from C, in C++ they do not carry the file extension.

  • Include the wrong code in the question, otherwise the answer seems unrelated to the question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.