473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

string::capacity()

18
Hi,
The string::capacity() returns the size of the allocated space, which is either equal or greater than this content size.
My question is: Is capacity assigning equal or greater than content size compiler dependent??
I've used the same function in a sample C++ program and compiled it with g++ compiler(linux) . The result is always equal to the content size but never greater.
can some one help me in clarifying this.
Jun 10 '08 #1
3 1935
gpraghuram
1,275 Expert 1GB
The string functions change according to the compiler as the implementation changes compiler to compiler.

Raghu
Jun 11 '08 #2
tcsvikr
18
The string functions change according to the compiler as the implementation changes compiler to compiler.

Raghu
Hi Raghu!!
Thanks for the reply.. I've observed the same in VC++ ..The implementation is different from linux
Jun 11 '08 #3
Banfa
9,065 Expert Mod 8TB
That is OK, as long as the string has enough memory for it's current contents then it is conforming to the standard.

There are several ways to implement a conforming String class and you may well find that different platforms exhibit different behaviour. That is why it is important to learn to write code that conforms to the standard and does not rely on the special behaviour of any one platform, especially if you intend the code to compile across different platforms.
Jun 11 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Axel | last post by:
Hiho, how can I reserve enough memory for a long string? I tried with max_size() but 4GB is to much for my system, an exception ist the result. And I'm getting an exception too when using the...
12
by: jl_post | last post by:
Dear C++ community, I have a question regarding the size of C++ std::strings. Basically, I compiled the following code under two different compilers: std::string someString = "Hello, world!";...
9
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a...
23
by: metaosp | last post by:
Hi, in the following code: string foo("foo"); foo.resize(10); foo.append("bar"); cout << foo << endl; // output is "foo" I expect the output to be "foobar", although "bar" is also
12
by: Avalon1178 | last post by:
Hi, I have an application that periodically uses a std::string variable which is assigned a VERY VERY large string (15000000+ bytes long). This application is essentially a daemon, and it polls...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
25
by: Bala2508 | last post by:
Hi, I have a C++ application that extensively uses std::string and std::ostringstream in somewhat similar manner as below std::string msgHeader; msgHeader = "<"; msgHeader += a; msgHeader...
7
by: Luna Moon | last post by:
#include "stdafx.h" #include <iostream> #include <string> using namespace std; int main() { string cc(31, 'c'); string bb=cc.assign(3, 'dd');
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.