Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doesn't recognize my string variable?

Status
Not open for further replies.

MCSGraham

Programmer
May 28, 2002
52
US
I'm trying to use a string variable and have it in my "public:" as: string Hold;

I have included <string.h> as one of my libraries too.

it doesn't recognize my string variable at all as if it's not connected to the string library or something? I found string.h on my computer so I know it should be good.

Any ideas as to how I might be able to get the program/Visual C++ 6.0 to see the <string.h> library and my string variable??

thanks in advance!
 
I think you need

#include <string>

(no .h on the end) and then refer to

std::string mystr;

as your variable. The string.h file is just the prototypes of string functions such as strcpy().
 
Thanks for the help! but that puts another problem now:

I'm trying to do an: outfile << mystr;

and it keeps giving me the error, (binary '<<' no operator defined which takes a right-hand operand of type &quot;class:std&quot;)

I need to be able to read in a string of characters until I reach a comma, then output this string to an output file.

I don't know why this isn't working right??
 
You probably need <fstream> or <iostream>. eg

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

...
{
ofstream outfile (&quot;cupid.txt&quot;);
string rope(&quot;ropey&quot;);

outfile << rope << endl;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top