•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,187 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,852 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 3380 | Replies: 11 | Solved
![]() |
•
•
Join Date: Mar 2007
Posts: 101
Reputation:
Rep Power: 2
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:
cplusplus Syntax (Toggle Plain Text)
std::string FirstName;
Or is it like this:
cplusplus Syntax (Toggle Plain Text)
char FirstName[] = "Blah blah";
The latter will require what I edited into my post later (that is, strlen).
tuxation.com - Linux articles, tutorials, and discussions
•
•
Join Date: Apr 2007
Location: Texas
Posts: 15
Reputation:
Rep Power: 2
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:
cplusplus Syntax (Toggle Plain Text)
const int ARRAY_SIZE = 10; string FirstName[ARRAY_SIZE]; // ... for (int i=0; i < ARRAY_SIZE; i++) { // ... }
tuxation.com - Linux articles, tutorials, and discussions
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
stringname[index].length()If 2, you create the string with
char stringname[10] then reference the length with strlen(stringname) Age is unimportant -- except in cheese
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- 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?



Linear Mode