| | |
string array size
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
strlen should work since you say you're using "string arrays" Last edited by John A; Apr 8th, 2007 at 12:06 am.
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Mar 2007
Posts: 159
Reputation:
Solved Threads: 0
ok here is what I got. I have
#include <string> and the for loop is
it still wont compile. now it says that left of length must have a class/strut/union type.
#include <string> and the for loop is
for (i = 0; i < FirstName.length(); i ++) { infile >> FirstName; }
it still wont compile. now it says that left of length must have a class/strut/union type.
How is
Does it look something like this:
Or is it like this:
The latter will require what I edited into my post later (that is, strlen).
FirstName declared?Does it look something like this:
C++ Syntax (Toggle Plain Text)
std::string FirstName;
Or is it like this:
C++ Syntax (Toggle Plain Text)
char FirstName[] = "Blah blah";
The latter will require what I edited into my post later (that is, strlen).
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Apr 2007
Posts: 15
Reputation:
Solved Threads: 2
What compiler are you using? I don't have the .length() function in MSVC++
To get what are you are trying do to do, the way I would do it would be:
To get what are you are trying do to do, the way I would do it would be:
C++ Syntax (Toggle Plain Text)
#include<vector> #include<string> //Then whatever goes in between //Declaration vector<string>FirstName(10); //For your loop for(i=0;i<FirstName.size();++i) infile>>Firstname[i]
Ah, I see what you're getting at.
Well, you could use the vector array example, or you could use a const to keep track of the array size:
Well, you could use the vector array example, or you could use a const to keep track of the array size:
C++ Syntax (Toggle Plain Text)
const int ARRAY_SIZE = 10; string FirstName[ARRAY_SIZE]; // ... for (int i=0; i < ARRAY_SIZE; i++) { // ... }
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
Do you mean to make
1) an array of 10 strings
2) a string to hold 10 characters?
If 1, you reference the length with
If 2, you create the string with
1) an array of 10 strings
2) a string to hold 10 characters?
If 1, you reference the length with
stringname[index].length()If 2, you create the string with
char stringname[10] then reference the length with strlen(stringname) The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- How do I convert a vector to a String array ? (Java)
- works for static need help to make it dynamic (C++)
- ArrayList to multi-dimensional string array (C#)
- Geting elements from a String Array (C++)
Other Threads in the C++ Forum
- Previous Thread: Setting Cursor position
- Next Thread: Assertion Failure?
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






