If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: basic string scope in std namespace

Re: basic string scope in std namespace

Originally Posted by Khiem

And again your program means its false. I am sad :sad:

umm ok?

If anyone has a real answer. I assume I am doing this the wrong way. Basically I am playing with cURL. I don't have a lot of experience with C++ as its my first project. I need to store the return data in a var. I don't know the best way to store the buffer since its going to be a variable length. My programing experience is all high level stuff like PHP. I have seen examples using the string lib but my use of it must not be right (or maybe g++ issue). Bottom line i'm confused why a var defined inside an if statement is outside the scope after it. I assume its the use of the string lib or the namespace.

Re: basic string scope in std namespace

I guess i am not thinking about scope the right way but your example works. But I do have another question. Is there a risk of a buffer over run if you reset the "the_string" and whats the char limit for string?

Re: basic string scope in std namespace

There is no limit* to the length of a string a string object can store. The string object will re-allocate the memory it stores internally if it needs to, to accomodate the longer string you assign to it.

*OK, there is a limit, but it's on the order of 2 billion, so for all practical purposes, there is no limit

Re: basic string scope in std namespace

I'm not familiar with cURL. However, there are two questions you need to ask:

1) Will this data ever need to be passed to a function expecting a (non-const) char*?
2) Is it possible to have a 0 byte prior to the end of the data? (I don't mean the character '0', I mean the NULL byte.)

If the answer to either of these is yes, you'll be better off with a std::vector<char>. Otherwise a std::string should be just fine.

Re: basic string scope in std namespace

I think I need to get my head wrapped around strings better first. I thought I had a grasp on what * was used for. But I am seeing it used in contexts I don't understand. I can see now why people pick python over C, but I really want to get a handle on this.

Re: basic string scope in std namespace

char* argv[] is simply an array of C-style strings corresponding to command-line arguments. You'll sometimes see the parameter declared as char ** argv, which is equivalent.

At the lowest level---where C lives---any string is just an array of characters. Hence the type is char*. However, classes such as std::string were creating specifically so that you wouldn't have to worry about such details. Consider the progression:

At each step we wrap a C++ class around a pointer, allowing us not to worry about the specifics of dealing with pointers. That's not to say that the three types are 100&#37; compatible in all cases, but they're essentially similar.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.