Programmers learn & share
+1 vote
11 views

Problem:

I am a new student of c++ programming. I am taking an online-based course to learn it. I’ve written a pretty simple program that adds two numbers through a function. I am attaching my code snippet below, please have a look:

int promptNumber()
{
    int n;
    std::cout << "Number: ";
    std::cin >> n;
    return n;
}

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

This is my io.cpp file. I’ve added both

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

header files starting on my main.cpp file but I can’t run the program. I keep getting an error: cout is not a member of std

Could any of you please shed some light on this?

by (12.9k points)   | 11 views

1 Answer

+1 vote

Solution:

You need to add the header file top of the io.cpp file too. Without the <iostream> header file the compiler never understands what to do with the codes. So, add the <iostream> header top of the io.cpp file then run the program. Then your program should run fine.

Good Day!

by (55.4k points)  
2,218 questions
2,683 answers
59 comments
241 users