Joe Laughlin posted:
Artie Gold wrote: Joe Laughlin wrote: #include <iostream>
int main()
{
std::string hello = "Hello World\n";
return 0;
}
This compiles fine. Is std::string defined in cstring?
Or is it included in iostream?
It is defined in <string>. The header <iostream>
evidently includes <string> on your implementation.
HTH,
--ag
Is it good practice to include the <string> header then?
I'd advocate it!
I even go one step futher:
#include <cstddef>
#include <cstring>
inline std::size_t strlenPlusNull(const char* const str);
{
std::size_t temp = std::strlen(str);
return temp += 1;
}
The function "strlen" returns an object of type "std::size_t". As such, if
you include the header that has "strlen" in it, then it simply must also
contain the definition of "std::size_t". But still... I like to include
"cstddef", whose actual job it is to define "std::size_t".
So for your program just there, I myself would do:
#include <iostream>
#include <string>
-JKop