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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string problem in C++

Status
Not open for further replies.

kook04

Programmer
Jun 26, 2001
58
US
Why am I getting an 'string : undeclared identifier' compile error for this line...

string s("hello");

I am including <string.h> in my file.

Thanks....Kennedy ------
Kennedy Roberts
 
Have you tried declaring the string in one step and then setting the value on the next (maybe VC doesn't like that constructor)?

Alternatively you can use CString.
CString words;
words = &quot;Whatever you want&quot;;
 
Yes, I tried that to no avail. It gives me the same error for CString also.

Kennedy ------
Kennedy Roberts
 
1. For the first problem you have to add this after your includes:

#include <iostream>
using namespace std;

2. For the second one with CString.
you cannot use CString in a program that has no MFC support. Anyway if you want to use MFC do this:
- go in ProjectSettings->General and select &quot;Use MFC in a Shared DLL&quot;
- add #include <afx.h> at the begining of your file, after your includes.

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
#include<string>
using namespace std;
string s=&quot;hello&quot;; John Fill
1c.bmp


ivfmd@mail.md
 
This is the one thing I didnt like. #include <string> and #include <string.h> are TWO different files. John is correct. #include <string> will give you the functionality you are missing.

Matt
 
Thank you everyone, my problem is now solved. ------
KJR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top