![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
String Array
How do i return the amount of elements within a string array!
script[i].Length() (shoudl work? haven't tried) script.Length() (doesn't work) any ideas?
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#2 | |
|
Professional Programmer
|
I don't understand why people post the question before they even try
..Yes, script[i].Length(); works.
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#3 |
|
Hobbyist
Join Date: Sep 2005
Posts: 266
Rep Power: 4
![]() |
sizeof(StringArray)/sizeof(StringArray[0]); Although I would suggest using std::vector instead of an array: std::vector<std::string> StringVector; size_t size = StringVector.size(); |
|
|
|
|
|
#4 |
|
Expert Programmer
|
maybe because thats no my question jayme... i know that it works!
i need to find out how many elemets are in the array no how many char's are in an element. Thanks Cache! New question void Engine()
{
// Error Initilizations
i_curError = 0;
s_errorArray[25] = 0x0;
}i get undeclared identifier error for both lines and why can't i return a damn string array!!! god damn't C# has corrupted my farkin mind! /*std::string[] Engine::ReturnErrors()
{
if(s_errorArray[0] != "")
return s_errorArray;
else
{
s_errorArray[0] = "none";
return s_errorArray;
}
}*/
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#5 | |
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,194
Rep Power: 5
![]() |
Quote:
[edit] Oh, you meant elements of the array, not elements of the string in the array. In that case, you can use sizeof(script)/sizeof(string), assuming that you allocated the space statically. If you are using dynamic allocation, you'll have to track it yourself, so if that is your intent, a vector is better, as Cache pointed out. [/edit]
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#6 | ||
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Quote:
Quote:
I would also recommend using a std::vector for your collection of strings, it's a lot easier to handle than dynamic arrays. |
||
|
|
|
|
|
#7 |
|
Expert Programmer
|
im familiar with vectors.. again im just attemping to port my code from C# to c++ as close as i can (hence the string array)
:banana: Oh and i didn't declare all of my variables... thats insulting? i forgot to post the class declaration. I do program for a living you can give me a little more credit than that lol. code is at work so i will write exactly what i have at work: class Engine
{
public:
Engine();
~Engine();
int i_curError;
std::string s_errorArray[25];
private:
//code at work
}
void Engine()
{
// Error Initilizations
i_curError = 0;
s_errorArray[25] = 0x0;
}
std::string[] Engine::ReturnErrors()
{
if(s_errorArray[0] != "")
return s_errorArray;
else
{
s_errorArray[0] = "none";
return s_errorArray;
}
}this bombs out for "undeclared identifier"... they are obviously declared...somehow the Constructor isn't being link to the class declaration. EDIT lectricpharaon: would this work -> [php] int len = sizeof(script)/sizeof(script[0]); [/php]
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#8 | |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Quote:
|
|
|
|
|
|
|
#9 | |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Quote:
void Engine()
{
// Error Initilizations
i_curError = 0;
s_errorArray[25] = 0x0;
}Engine::Engine()
{
// stuff here
} |
|
|
|
|
|
|
#10 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|