Visual C++ and STL!!
Hi.
I am trying to compile a code that does RLE (run length encoding) using string's (STL).
When I compile, I get errors referring to all string declarations.
But it ignores the line declaring the header '#include <string>'.
Do I need to link something in the settings for it to compile strings and other STL routines?
I've always had trouble compiling STL stuff with my Visual Studio/C++. Everywhere else it compiles and runs fine.
~ I'm a wannabe programmer ~
1) Make sure you have the latest service pack.
2) Strings should be in the namespace std, so declare you strings as std::string or put "using namespace std" before you use the strings.
2) Strings should be in the namespace std, so declare you strings as std::string or put "using namespace std" before you use the strings.
Also make sure that you are not using the old, pre-standard headers. The STL is now called the C++ standard library, and its files no longer have the .h file extension. If you are using prestandard headers, then it is possible that some parts may be different across compilers.
Example:
If you need more help, could you give us the exact error message you get?
Edited by - null_pointer on December 31, 2001 5:59:34 PM
Example:
#include <iostream.h> // old#include <iostream> // new
If you need more help, could you give us the exact error message you get?
Edited by - null_pointer on December 31, 2001 5:59:34 PM
When you are declaring strings, are you fully qualifying the name?
e.g. std::string ...
or else you could do something like
#include
using namespace std;
then you can just declare strings like
string ...
without the std::
Shabadoo
e.g. std::string ...
or else you could do something like
#include
using namespace std;
then you can just declare strings like
string ...
without the std::
Shabadoo
Along the same lines as already mentioned, if you are using only a few classes from the STL, you can avoid possible namespace collisions by only ''using'' the classes you need. For example, if you use only the string class, you can put
using std::string;
in your header and then use the string class without the std prefix.
using std::string;
in your header and then use the string class without the std prefix.
Ok, I havent used the STL too much, although I have used vectors, maps, and strings before. However, I''ve used them in a Unix environment and on "web-compilers".
But I dont recall ever using namespace.
I will try that...and I bet it will work.
I''ll leave with this....
what the heck is a namespace std?
~ I''''m a wannabe programmer ~
But I dont recall ever using namespace.
I will try that...and I bet it will work.
I''ll leave with this....
what the heck is a namespace std?
~ I''''m a wannabe programmer ~
quote:Original post by GekkoCube
what the heck is a namespace std?
Ask Google. Or RTFM.
[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
OK.
Now I know what namespace is, although roughly.
But does anybody know what i can store an integer value in a character variable while retaining its integer value?
ex:
int number = 5;
char var = number; // this doesnt retain "number''s" value of 5.
~ I''''m a wannabe programmer ~
Now I know what namespace is, although roughly.
But does anybody know what i can store an integer value in a character variable while retaining its integer value?
ex:
int number = 5;
char var = number; // this doesnt retain "number''s" value of 5.
~ I''''m a wannabe programmer ~
GekkoCube,
int number = 5;
char var = number;
if(var * 2 == 10)
{
printf("Success!\n";
}
This works fine. What are you talking about?
A char is just a single-byte number that happens to also be useable for strings. Just like a wchar is a double-byte number that can be used for wide strings.
int number = 5;
char var = number;
if(var * 2 == 10)
{
printf("Success!\n";
}
This works fine. What are you talking about?
A char is just a single-byte number that happens to also be useable for strings. Just like a wchar is a double-byte number that can be used for wide strings.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement