# Beginner C++ error



## z662 (Mar 30, 2010)

I am new to C++, and am running into an error that seems rather simple to fix but am lacking an understanding of how to do so.  I want to assign the value that string.length() returns to a variable so I thought I would use something like 'size_t'  However from what I have read it looks like you need to use a typedef to do so properly.  I tried 'typdef unsigned int size_t' but that did not work.  I then tried a few variations to no avail.  I have been using this link as a reference but do not understand their typedef in the slightest. http://www.cplusplus.com/reference/string/string/length/Does anyone know how to do what I am trying to do??


----------



## expl (Mar 30, 2010)

```
#include <cstring>
```

Type size_t is defined there.


----------



## z662 (Mar 30, 2010)

Thanks expl that worked... however I was hesitant to use that in the first place because I wanted to do it the 'CPP' way and I thought based on that name it was something from C.  Is that true? Or is also true that all original C include files all end with '.h'?  I just assumed that cstring was from legacy C include files.  As I said...just starting out.  I apologize for the noob-like questions.


----------



## doena (Mar 30, 2010)

The c prefixed includes of standard c-headers e.g. "cstdio" were made as forwarding
headers for c++ to include standard c-functions, defines, datatypes that are in c++'s
default namespace std (please correct me if I'm wrong)!


----------



## expl (Mar 30, 2010)

Indeed, cstring is a forwarding header for the libc's "string.h".


----------



## Oxyd (Mar 30, 2010)

And yes, if you want to use things like std::size_t and others (and it's good that you want to use them), you'll have to use the "C legacy" <csomething> headers.


----------



## z662 (Mar 30, 2010)

Oh ok, well that is good, I am happy that it was indeed a simple fix.  So to clarify 'size_t' in C++ is the same as it was in C but 'updated' or whatever to be fully compatible.  And it is also the proper way to do what I am doing?  I just want to make sure it is proper, based on what Oxyd said it seems to be so at least.


----------

