Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with vector::size_type

Started by Sagar_Indurkhya Jul 10, 2004 at 11:47 AM 5 replies 1.2k views
Original Post
Sagar_Indurkhya
Sagar_Indurkhya
How do I get the size of a vector containing strings? I want to convert it to a string, but I get lots of errors.
TangentZ
TangentZ
The size of a vector (and other STL containers) is given by its
size() function.

vector<string> vs;vector<string>::size_type siz = vs.size(); // The size of the vector.


Maybe you can post some code so we can see what's wrong.
神はサイコロを振らない!
Fruny
Fruny
Is it a vector of strings you want to concatenate?
Are you trying to turn the vector length ('it') into a string?
Are they C strings or C++ strings?
Where does size_type come into play?
What errors do you get?
Care to show some code?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Sagar_Indurkhya
Sagar_Indurkhya
I want to convert the length of the vector, as in number of objects, to an int. When I just use the size function, it says I have to have some other stuff.

I want to do some thing like this:

for(int i = 0; i < names.size(); i++){     names = "empty";}


Corvwyn
Corvwyn
I'm not 100% sure what the problem is here, but it might be something else than the size() function that is the problem. This works however:

#include <iostream>#include <vector>#include <string>using namespace std;int main(){	vector<string> names;	for(int i=0;i<(signed)names.size();++i)	{		names = "empty";	}	return 0;}
Kylotan
Kylotan
They are like pointers. You increment them to move from one item in a container to the next. There's an STL link in my signature, and the documentation there contains a summary of iterators which might help you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.