Link to home
Create AccountLog in
Avatar of w3ttfyre
w3ttfyre

asked on

C++ String Parsing, Vectors, And File I/O

Hello, I would like to find a website or a tutorial (can be your own) that will teach me about Vectors and string parsing. Preferably designed for a newer programmer. Also I would like to learn about File  I/O. Specifically How to read and write to specific lines. Like writing to line 1 - A, Line 2- B, Line 3 -C:

A
B
C

like that. Thanks a ton.

(I Can Raise The Point Value If U Think My Point Value Is Too Low, Don't Be Afraid If It Really Is)
Avatar of trigger-happy
trigger-happy
Flag of Philippines image

Do you want a string parser or maybe just a splitter? If second, have a look to:
http://www.codeproject.com/string/stringsplit.asp
Avatar of Paul Maker
you need to look at the C++ STL. this contains the vector class for array handling and the string class for string handling. string parsing will be specific to your task in hand so i suggest you see the type of methods availiable in the string class. File IO can be handled with the ifstream classes etc..

example

#include <vector>
#include <string>
using namepsace std;

vector<int> my_ints;
my_ints.push_back(1);
my_ints.puch_back(2);
for(int i = 0; i < my_ints.size() ; i++)
{
   cout<<my_ints[i]<<endl;
}

string my_string = "hello world";
int w_pos = my_string.find("w");
cout<<"w is at string pos : "<<w_pos<<endl;
ASKER CERTIFIED SOLUTION
Avatar of wayside
wayside

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of w3ttfyre
w3ttfyre

ASKER

can any1 tell me in what case i would use a vector and/or is there something that is similar to a vector that has advantages/disadvantages?

Be Back 2morrow
It depends on what is more important to you, fast access or fast insertions and deletions:

vector:  Allow fast random access to any element. They should be the preferred container when random-access performance is the priority. They allow constant time insertions and deletions at the end of the sequence. Inserting or deleting elements in the middle of a vector requires linear time.

deque: like vector, but also allows fast insertion and deletion at the front of the container

list: allow efficient insertions and deletions at any location within the sequence. The sequence is stored as a bidirectional linked list of elements.

map: efficient for looking up values that  are associated with a unique key. Depending on your requirements, the values can be stored in a sorted manner, which provides insertion, deletions, and lookups with log n efficiency, or based in a hash function (hash_map) which provides inserts, deletions. and lookups in constant time.