Visual C++ and STL!!

Started by
9 comments, last by GekkoCube 22 years, 3 months ago
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 ~
Advertisement
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.
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
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
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.
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 ~
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 ~
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.


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 ~

This topic is closed to new replies.

Advertisement