Curious behavior.

I have a project in that I have file real.h and all project it runs rightly.

With the F11 in Code:: Blocks I create real.cpp and put as header #include “real.h”

Immediately it creates to me problem in following prototype which is in header of real.h

Why it makes him this?

real.h
--------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef REAL_H_INCLUDED
#define REAL_H_INCLUDED

#include <cmath>

template <typename T>
std::string to_string(T value)
{
    std::ostringstream os ;
    os << value ;
    return os.str() ;
}

...................


real.cpp
---------------
#include "real.h"

include\real.h|9|error: 'string' in namespace 'std' does not name a type|
Last edited on
You seem to have forgotten to include the string header. It's an easy enough mistake to make.
you need to

1
2
#include <sstream>
#include <string> 


while you can remove line 4
OK it works, thanks, but why?
only real.cpp i add.
Without real.cpp i have no problem at all.



---------------
#include "real.h"

It is probably because you happened to include sstream and string before you were using real.h in your other .cpp files.

Then when you created real.cpp it tried to include real.h and failed at compiling because sstream and string weren't included.
Thank you very much.
Topic archived. No new replies allowed.