473,569 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

length of a string

Hi,

I'm reading from a .dat file and I want to know the length of the
string .

I' using the stringRef.lengt h () but the compiler said there was an
error

`stringRef' undeclared (first use this function)

Is there any function in C++ to determine the lenght of the string??
Cheers!

Mar 20 '06 #1
8 7812
TB
cd********@yaho o.co.uk skrev:
Hi,

I'm reading from a .dat file and I want to know the length of the
string .

I' using the stringRef.lengt h () but the compiler said there was an
error

`stringRef' undeclared (first use this function)

Is there any function in C++ to determine the lenght of the string??


? Read the error message!

--
TB @ SWEDEN
Mar 20 '06 #2
cd********@yaho o.co.uk wrote:
Hi,

I'm reading from a .dat file and I want to know the length of the
string .

I' using the stringRef.lengt h () but the compiler said there was an
error

`stringRef' undeclared (first use this function)

Is there any function in C++ to determine the lenght of the string??


Your problem is not a missing function (it is there, trust me), but
a missing string. Cannot determine the length of something that is not
there, can you?

If you still cannot figure out what you are doing wrong, try:

#include <string>

int main ()
{
std::string s = "Hello";
s.length ();
}

hth
--
jb

(reply address in rot13, unscramble first)
Mar 20 '06 #3
cd********@yaho o.co.uk wrote:
Hi,

I'm reading from a .dat file and I want to know the length of the
string .
What string? What is a .dat file?
I' using the stringRef.lengt h () but the compiler said there was an
error

`stringRef' undeclared (first use this function)
Well, then I guess you forgot to declare stringRef.
Is there any function in C++ to determine the lenght of the string??


Yes, the lenght() member function (if you are referring to std::string).

Mar 20 '06 #4
<cd********@yah oo.co.uk> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
Hi,

I'm reading from a .dat file and I want to know the length of the
string .

I' using the stringRef.lengt h () but the compiler said there was an
error

`stringRef' undeclared (first use this function)

Is there any function in C++ to determine the lenght of the string??


Yes, it is indeed .length() for std::string

It sounds more like your std::string stringRef is undefined. Most likely
you have a typo and misstyped the name of the function. Are you sure it
shouldn't be StringRef or soemthing? Compare where you declared stringRef
and how you're using it.

stringRef should be declared something like:
std::string stringRef;
Mar 20 '06 #5

"TB" <TB@SWEDEN> wrote in message
news:44******** **************@ taz.nntpserver. com...
cd********@yaho o.co.uk skrev:
Hi,

I'm reading from a .dat file and I want to know the length of the
string .

I' using the stringRef.lengt h () but the compiler said there was an
error

`stringRef' undeclared (first use this function)

Is there any function in C++ to determine the lenght of the string??


? Read the error message!


Would that be "RTEM"? :-)
Mar 20 '06 #6

Rolf Magnus wrote in message ...
"""""""
cd********@yaho o.co.uk wrote:
I' using the stringRef.lengt h () but the compiler said there was an
error
`stringRef' undeclared (first use this function)
Well, then I guess you forgot to declare stringRef.
Is there any function in C++ to determine the lenght of the string??


Yes, the lenght() member function (if you are referring to std::string).
"""""""

Don't forget to define it first:

#include <string> // C++
#include <iostream>
#include <ostream> // std::endl

size_t lenght(std::str ing const &Tstr){
return Tstr.size();
// or: return Tstr.length();
}

int main(){
std::string stringRef( "Yes, the lenght() member" );
std::cout<<" size of stringRef is "<<lenght( stringRef )<<std::endl;
return 0;
}

// output: size of stringRef is 24

--
Bob <G> R
POVrookie
Mar 21 '06 #7

"BobR" <Re***********@ worldnet.att.ne t> wrote in message
news:Vl******** *************@b gtnsc05-news.ops.worldn et.att.net...

Rolf Magnus wrote in message ...
"""""""
cd********@yaho o.co.uk wrote:
I' using the stringRef.lengt h () but the compiler said there was an
error
`stringRef' undeclared (first use this function)


Well, then I guess you forgot to declare stringRef.
Is there any function in C++ to determine the lenght of the string??


Yes, the lenght() member function (if you are referring to std::string).
"""""""

Don't forget to define it first:

#include <string> // C++
#include <iostream>
#include <ostream> // std::endl

size_t lenght(std::str ing const &Tstr){
return Tstr.size();
// or: return Tstr.length();
}

int main(){
std::string stringRef( "Yes, the lenght() member" );
std::cout<<" size of stringRef is "<<lenght( stringRef )<<std::endl;
return 0;
}

// output: size of stringRef is 24


May I assume we're actually talking about the "length" function here, not
the "lenght" function? :-)

Mar 21 '06 #8

Howard wrote in message ...

"BobR" <Re***********@ worldnet.att.ne t> wrote in message ...

Rolf Magnus wrote in message ...
"""""""
Is there any function in C++ to determine the lenght of the string??


Yes, the lenght() member function (if you are referring to std::string).
"""""""

Don't forget to define it first:

#include <string> // C++
#include <iostream>
#include <ostream> // std::endl

size_t lenght(std::str ing const &Tstr){
return Tstr.size();
// or: return Tstr.length();
}

int main(){
std::string stringRef( "Yes, the lenght() member" );
std::cout<<" size of stringRef is "<<lenght( stringRef )<<std::endl;
return 0;
}
// output: size of stringRef is 24


May I assume we're actually talking about the "length" function here, not
the "lenght" function? :-)


Wal, ewe dint want me two tel hymn he spelt sumthin rong didja?
<G>

Anyway, maybe the OP will see something that will help them. (...and I,
hopefully, at least got a chuckle out of somebody).

The question is, does '*.length()' return '*.size()', or does '*.size()'
return '*.length()'?
Neither! Looking at my (MinGW GCC) basic_string.h:

// Capacity:
size_type size() const { return _M_rep()->_M_length; }
size_type length() const { return _M_rep()->_M_length; }

So, either one is as good as the other. (no extra 'call overhead')
--
Bob <G> R
POVrookie
Mar 21 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2341
by: John Smith | last post by:
Hi, I'm writing a library in C++ which is supposed to be used by people using C. One function I have must return a string to users which is arbitrary length. The user must be able to use this string as "char *" so I was wondering if the following construct is safe: char *Func() { static string str;
5
11728
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 MyString As String Am I getting VLS declaration or a FLS declaration? Can I control which I get somehow? I have done some homework, but I don't...
3
29221
by: Jimski | last post by:
Hello all, I am having a problem where I get an error message when I call FlushFinalBlock when decrypting my encrypted text. I am using the Rijndael algorithm. The error message is "Length of the data to decrypt is invalid" and occurs on the csDecrypt.FlushFinalBlock.
1
5295
by: gane kol | last post by:
Hi I am using DES algorithm. I am getting an error message in a few cases of the querystring Error Message : Length of the data to decrypt is invalid. Error Method : System.String Decrypting(System.String) Error Line: strDecrpt = sr.ReadToEnd(); QueryString Data:
7
2536
by: Matt | last post by:
Have below code AcctNbr give me result of 30. That is the database column length, Column stores 10 why is giving me 30 ? while(objRead.Read()) { AcctNbr = (string)objRead.ToString().Length; Console.WriteLine("Length is {0}",AcctNbr.Length); }
10
4566
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 zero-length string (always returns a zero-length string when used in a query expression)" **** How many records are there in FirstTable in which...
10
4297
by: Mavenos | last post by:
Hi Web Masters, Just wondering wether you can help us to come up with some tokenize script. My problem is wanted to display a LONG content into a short para (by giving minimum letter lenght) I mean if I have a 2 page content - just I want to display only 4 lines having 200 letters then follows the content with "....." at the end of
1
8011
by: Sathyaish | last post by:
I have the following scenario: Algorithm: 3DES Cipher Mode: CBC Key Size: 128-bit Block Size: 64 bit IV: 0x0000000000000000 (an eight byte array of zeros) The results I get using .NET with the following routine are:
6
9253
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will = "kelly" with no error // but string s2 = "kelly".Substring(0,200) // results in // ArgumentOutOfRangeException
1
9407
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 form data in a fixed length structure that is written direct to disk. I need to load the existing files, into a fixed length structure to...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.