0

The Directives for string

Hey 😊 I tried to exclude #include<string> and just have the iostream as per the little description on the 'Strings' tab, and the program failed to work. When I tried the other way around... that failed as well. What am I doing wrong?

10th Jan 2018, 5:18 AM
Aaron Meighoo
Aaron Meighoo - avatar
4 Respostas
+ 8
Some compilers automatically include the <string> header for you when you include <iostream>, but there is no guarantee for it to happen. VS compiler, for example, does not. Hence, it is encouraged that you include the <string> header whenever your code involves the use of std::string.
10th Jan 2018, 5:27 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Post your code please. It will be easier to answer.
10th Jan 2018, 5:20 AM
Matej Novotný
Matej Novotný - avatar
+ 1
Oh, I understand now, thank you. I am, in fact using Visual Studio so that explains it. ☺️
10th Jan 2018, 5:31 AM
Aaron Meighoo
Aaron Meighoo - avatar
- 1
I'm working on something bigger, but this is what I was testing to find an efficient method: #include <iostream> #include <string> #include <cstdlib> int Main() { std:: string word; std::course << "Please enter a word\n\n"; std::cin >> word; system("pause"); return 0; }
10th Jan 2018, 5:25 AM
Aaron Meighoo
Aaron Meighoo - avatar