I have used #include<string.h> and then declared String str1, str2; and have not been able to use cin>>str1; after prompting for input.
Printable View
I have used #include<string.h> and then declared String str1, str2; and have not been able to use cin>>str1; after prompting for input.
try using the function: getline (cin, stringname,'\n'); to see what happen.
dh
use it without capitals.
#include <string.h>
string strFile;
mtighe,
[email protected]
You have 3 problems:
1. The header file is included as <string> (instead of <string.h>)
2. The class you need is string (not String).
3. To use the string class directly, you need to declare the std namespace at the top of the file:
using namespace std;
Cheers!
Alvaro
In reply to:
3. To use the string class directly, you need to declare the std namespace at the top of the file:
using namespace std;
If you're just using one (or even just a few) things from the standard library, it's it's better to insert the individually into the global namespace, instead of dragging the entire library in:
using std::string;
using std::cin;
string Str1, Str2;
cin >> Str1;
Sometimes, it's best just to qualify the name where it's used:
std::string Str1, Str2;
std::cin >> Str1;
Truth,
James