cout no es miembro de std


Estoy practicando el uso de archivos mulitple y archivos de encabezado, etc. Así que tengo este proyecto que toma dos números y luego los suma. Bastante simple.

Aquí están mis archivos:

Main.cpp

#include <iostream>
#include "add.h"

int main()
{
    int x = readNumber();
    int y = readNumber();

    writeAnswer(x + y);

    return(0);
}

Io.cpp

int readNumber()
{
    int x;

    std::cout << "Number: ";
    std::cin >> x;

    return x;
}

void writeAnswer(int x)
{
    std::cout << "Answer: ";
    std::cout << x;
}

Add.h

#ifndef ADD_H_INCLUDED
#define ADD_H_INCLUDED

int readNumber();
void writeAnswer(int x);

#endif // #ifndef ADD_H_INCLUDED

El error aparece en io.cpp. Los errores exactos son:

introduzca la descripción de la imagen aquí

¿Alguien tiene alguna idea de por qué esto puede estar sucediendo? Gracias.

EDITAR: Hice un pequeño proyecto ayer con la misma cantidad de archivos (2 .cpp y 1.h )y no incluí el encabezado iostream en el otro.cpp y todavía compiló y funcionó bien.

Author: Ernestas Gruodis, 2012-07-07

3 answers

Añade #include <iostream> al comienzo de io.cpp también.

 230
Author: unkulunkulu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-07 14:45:29

Tuve un problema similar y resultó que tuve que agregar una entrada adicional en cmake para incluir los archivos.

Dado que también estaba usando la biblioteca zmq, tuve que agregar esto a las bibliotecas incluidas también.

 1
Author: Marco Rubio,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-22 17:26:16

También recuerde que debe ser:

#include "stdafx.h"
#include <iostream>

Y no al revés

#include <iostream>
#include "stdafx.h"
 1
Author: Jukes,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-20 19:41:51