|
From: Jason H. <jas...@bt...> - 2001-10-21 22:02:38
|
Hi, your problem is that you are mixing up the string header for the C =
string functions i.e. strlen(), strcat(), etc... and that for the string =
object which is part of C++.
#include <string>
Is the one you want. Note the lack of the ".h"; this has become standard =
in C++. Also <string.h> and <cstring> (no ".h") are the same header.... =
well, almost but it makes no difference in the current mingw version. =
All the old style C headers i.e. <stdlib.h> <stdio.h> have now been =
moved on to the new form in C++ i.e. <cstdlib> <cstdio>, and the old =
form is depreciated, but still usable at the current time.
Basically you can just delete all the .h's off the includes in your code =
below.
Jason.
----- Original Message -----=20
From: Daniel Anderson=20
To: dev...@li...=20
Sent: Sunday, October 21, 2001 6:38 PM
Subject: [Dev-C++] using strings
Hello,
A seemingly simple problem has stumped me so far. I cannot figure out =
how to use simple strings in my programs. Do I need to add the =
<cstring.h> library? If so, my compiler says it can't find it- can I =
download this somewhere? I know I can get around this problem by using =
an array of chars, but I want to be able to use strings. I am using Dev =
4.01 and the mingw compiler 2.95.2-1. A thousand thanks for any help.
D
When I try to compile this program, I can a 'string' undeclared (first =
use this function) error.
// start
#include <iostream>
#include <iomanip> // For setw()
#include <fstream> // For file I/O
#include <string>
using namespace std;
int main()
{=20
string s1;
char pause;
cin >> s1;
cout << endl << s1 << endl;
cout << "pause";
cin >> pause;
return 0;
}
|