how to use stl?
-
;)I have writen a program : #include using namespace std; int main() { string a("a"); return 0; } when i compile it then it is the result : --------------------Configuration: abc - Win32 Debug-------------------- Compiling... abc.cpp c:\program files\microsoft visual studio\vc98\include\xstring(600) : error C2838: illegal qualified name in member declaration c:\program files\microsoft visual studio\vc98\include\xstring(618) : see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>' being compiled c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2629: unexpected 'class std::logic_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2146: syntax error : missing ';' before identifier '_Str' c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: 'string' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: '_Str' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2629: unexpected 'class std::domain_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2629: unexpected 'class std::invalid_argument (' c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2629: unexpected 'class std::length_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2629: unexpected 'class std::out_of_range (' c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2629: unexpected 'class std::runtime_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2334: unexpe
-
;)I have writen a program : #include using namespace std; int main() { string a("a"); return 0; } when i compile it then it is the result : --------------------Configuration: abc - Win32 Debug-------------------- Compiling... abc.cpp c:\program files\microsoft visual studio\vc98\include\xstring(600) : error C2838: illegal qualified name in member declaration c:\program files\microsoft visual studio\vc98\include\xstring(618) : see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>' being compiled c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2629: unexpected 'class std::logic_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2146: syntax error : missing ';' before identifier '_Str' c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: 'string' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: '_Str' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2629: unexpected 'class std::domain_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2629: unexpected 'class std::invalid_argument (' c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2629: unexpected 'class std::length_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2629: unexpected 'class std::out_of_range (' c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2629: unexpected 'class std::runtime_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2334: unexpe
why dont u use the class CString?
-
why dont u use the class CString?
Because it's an STL exercise. Just because someone gets an error with STL does not automatically warrant a "Use MFC" comment. :rolleyes:
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
;)I have writen a program : #include using namespace std; int main() { string a("a"); return 0; } when i compile it then it is the result : --------------------Configuration: abc - Win32 Debug-------------------- Compiling... abc.cpp c:\program files\microsoft visual studio\vc98\include\xstring(600) : error C2838: illegal qualified name in member declaration c:\program files\microsoft visual studio\vc98\include\xstring(618) : see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>' being compiled c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2629: unexpected 'class std::logic_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2146: syntax error : missing ';' before identifier '_Str' c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: 'string' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: '_Str' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2629: unexpected 'class std::domain_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2629: unexpected 'class std::invalid_argument (' c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2629: unexpected 'class std::length_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2629: unexpected 'class std::out_of_range (' c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2629: unexpected 'class std::runtime_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2334: unexpe
edit your post so that we can see your include btw, include this:
#include <STRING>
You don't know where to start ? ask a good friend
-
;)I have writen a program : #include using namespace std; int main() { string a("a"); return 0; } when i compile it then it is the result : --------------------Configuration: abc - Win32 Debug-------------------- Compiling... abc.cpp c:\program files\microsoft visual studio\vc98\include\xstring(600) : error C2838: illegal qualified name in member declaration c:\program files\microsoft visual studio\vc98\include\xstring(618) : see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>' being compiled c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2629: unexpected 'class std::logic_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2146: syntax error : missing ';' before identifier '_Str' c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: 'string' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: '_Str' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2629: unexpected 'class std::domain_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2629: unexpected 'class std::invalid_argument (' c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2629: unexpected 'class std::length_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2629: unexpected 'class std::out_of_range (' c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2629: unexpected 'class std::runtime_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2334: unexpe
The code you've shown is fine. Something else is at play, like using the /Za compiler switch.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
edit your post so that we can see your include btw, include this:
#include <STRING>
You don't know where to start ? ask a good friend
I agree, it seems as if you forgt an "#include" statement or some needed setting is not set properly.
-
;)I have writen a program : #include using namespace std; int main() { string a("a"); return 0; } when i compile it then it is the result : --------------------Configuration: abc - Win32 Debug-------------------- Compiling... abc.cpp c:\program files\microsoft visual studio\vc98\include\xstring(600) : error C2838: illegal qualified name in member declaration c:\program files\microsoft visual studio\vc98\include\xstring(618) : see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>' being compiled c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2629: unexpected 'class std::logic_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2146: syntax error : missing ';' before identifier '_Str' c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: 'string' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: '_Str' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2629: unexpected 'class std::domain_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2629: unexpected 'class std::invalid_argument (' c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2629: unexpected 'class std::length_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2629: unexpected 'class std::out_of_range (' c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2629: unexpected 'class std::runtime_error (' c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2334: unexpe
It should work. Are you using pre-compiled headers? If so did you put the stdafx.h before the string include?
-
edit your post so that we can see your include btw, include this:
#include <STRING>
You don't know where to start ? ask a good friend
A small knit pick, but you should use lowercase.
Steve
-
why dont u use the class CString?
And what does he use if he can't get that to work?
Steve
-
A small knit pick, but you should use lowercase.
Steve
why ? i always include the standard C++ headers in uppercase, as the include file names are written like that... please explain your feeling
You don't know where to start ? ask a good friend
-
why ? i always include the standard C++ headers in uppercase, as the include file names are written like that... please explain your feeling
You don't know where to start ? ask a good friend
It is standard practice when writing portable code. On some systems, such as Linux, the file system is case sensitive. The standard headers are required to be lowercase.
Steve