#include inside a function

Hi,

I am trying to "transfer" a part of my main program that needs the libraries stdio.h and sstream to an external function (another ".cpp", in the same project in Visual C++ Express), that I will eventually call in the main program.

Though, when I include:
1
2
#include <stdio.h>
#include <sstream> 

I still can't use cout or string. Is that normal?
Thank you

Sky
Last edited on
std::cout and std::string

you'll need the scope resolution operator if you haven't included the proper using declarations

Also I don't think #includes belong in functions, I thought they should always be global for a file.
std::cout is defined in <iostream>
std::string is defined in <string>
1
2
#include <iostream>
#include <string>  


What include does is that it just copy paste the file content into the file. You shouldn't include header files inside function because that will often not work and even if it works it's not what you want.

I have seen includes used inside functions but then the file that was included was not a normal header file. It was just a file with some code in it.
Topic archived. No new replies allowed.