473,320 Members | 2,083 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.

Length of string object

94 64KB
Hi, everyone. Please consider the following code:

Expand|Select|Wrap|Line Numbers
  1. string input;
  2.  
  3. getline( std::cin, input )
In the code above, what is the maximum number of characters that can be read into variable input? Thanks a lot in advance!
May 7 '14 #1
4 1390
Luk3r
300 256MB
I believe it's partially machine dependent. The below code will tell you what the size of your string is and the maximum size allowed. Size of strings doesn't always just count characters. It depends on concatenation also, which is why I provided code that will show your string length and max string length.

Expand|Select|Wrap|Line Numbers
  1.  {
  2.   std::string str ("Test string");
  3.   std::cout << "size: " << str.size() << "\n";
  4.   std::cout << "max_size: " << str.max_size() << "\n";
  5.   std::cin.get();
  6.   getchar();
May 7 '14 #2
stdq
94 64KB
Interesting. I didn't know about function max_size(). Thanks!
May 7 '14 #3
stdq
94 64KB
My original code is incorrect. The call to getline should be as follow:

Expand|Select|Wrap|Line Numbers
  1. std::cin.getline(arg1, arg2)
where arg1 is of type char * and arg2 an integer.
May 7 '14 #4
stdq
94 64KB
Actually, I think both forms are correct...
May 7 '14 #5

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

Similar topics

2
by: July | last post by:
Hello all Recentlly, I was asked to write a program in which there is a function that need to reverse a std::string object. I wrote like this: string ReverseString(const string& srcStr) {...
5
by: MLH | last post by:
I'm working with lots of long strings now, it seems. I have to import them & parse them constantly. The A97 memo field type supports only 32768 chars. What happens when this is processed... Dim...
1
by: Guadala Harry | last post by:
What do to about conversion to decimal type when blank is allowed? The situation is this. In the UI there is a textbox into which users can enter a value which is supposed to be a dollar amount....
4
by: Scott Lemen | last post by:
Hi, Some Win APIs expect a structure with a fixed length string. How is it defined in VB .Net 2003? When I try to use the FixedLengthString class I get an "Array bounds cannot appear in type...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
1
by: Rick Knospler | last post by:
I am trying to convert a vb6 project to vb.net. The conversion worked for the most part except for the fixed length strings and fixed length string arrays. Bascially the vb6 programmer stored all...
3
by: Coll | last post by:
I inherited a database. On one of the forms, a bunch of fields on the form are to be updated with data from a combo box containing many columns after one particular field is updated. I'm receiving...
2
by: =?Utf-8?B?Z3Jva25yb2xs?= | last post by:
Is there a way that I can define a WebMethod with a parameter that is a fixed length string? I'm using VB.Net 2005 and would like to define a webmethod that will prevent the caller from passing a...
3
by: angi35 | last post by:
I'm having a zero-length string problem... Hoping someone can help. (This is in Access 2000.) In FormA, I have a button that opens FormB with OpenArgs. In FormB, the OpenArgs are translated into...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.