Archived

This topic is now archived and is closed to further replies.

GekkoCube

Visual C++ and STL!!

Recommended Posts

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 ~

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:

#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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ~

Share this post


Link to post
Share on other sites
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 ~

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.


Share this post


Link to post
Share on other sites
I have an array of type char.
I use the array to store letters and numbers.

When I am done storing into my array, I print each element of the array to the screen.
But I noticed that when I display a number, it is not a number, but they are just "junk characters."

~ I''''m a wannabe programmer ~

Share this post


Link to post
Share on other sites