strings with vectors??
I am still new to vectors, although ,I am trying to input some strings and then sort them. Here is an example: reading in some names then sorting the names. I have already done this by making an array of structs, even by using an array of classes. Here is an example:
struct
{
char mybuffer[99];
} buffer[99]
for (int i = 0; i < num; i++)
cin.getline >>(buffer.buffer, 98);
.
.
.
Then I used a bubble search to sort it. But I want to use vectors so I rewrote the program using vectors but the vectors were only reading in one char not a whole string. Any suggestion on how to read in a string into vectors? Thx.
-----------------------------
"There are ones that say they can and there are those who actually do."
"...u can not learn programming in a class, you have to learn it on your own."
Edited by - cMADsc on May 1, 2001 4:48:18 PM
Edited by - cMADsc on May 1, 2001 6:11:23 PM
-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."
I''m surprised your previous code worked.
Is this what you want?
This has a bug. It asks for (buffer.size() + 1) number of input. I don''t know why. Never had much success with cin.getline().
Jinushaun
Is this what you want?
|
This has a bug. It asks for (buffer.size() + 1) number of input. I don''t know why. Never had much success with cin.getline().
Jinushaun
JinushaunNation Leprechaun
How about this code:
Edited by - JungleJim on May 2, 2001 5:24:27 AM
|
Edited by - JungleJim on May 2, 2001 5:24:27 AM
Some useful C++ links:Free multiplatform ANSI C++ Standard Library implementationVisual C++ 6.0 STL fixesVisual C++ 6.0 noncompliance issuesC++ FAQ Lite
Yeah, why don''t you use std::string? (see JungleJim''s code) unless it''s a major inconvenience to change all your code to use that, I don''t see why not. Btw, my code sample didn''t use stl string for that reason.
Jinushaun
Jinushaun
JinushaunNation Leprechaun
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement