getline from a matrix

Hello there,

I want to know how can I use the line from a matrix as the source for a getline function. I have a matrix that stores several web pages. Each line of this matrix is the complete address of the web page and each row represents a single letter. What I must do is to read the web sites in my matrix one by one.

To get the web pages from the text file I use
1
2
ifstream file;
file.open("test.txt");


But I have no idea how to make the matrix my source for the getline.

If you need more explanations let me know. Oh and btw this my second month of programing so apart from some basic C++ we haven't learned all that much yet.

P.S. The program is written in C++.
Just to be clear, you have a file with a list of URLs and you want your program to download the contents of these URLs. Is that correct?
Yes I have that list, but I already stored its contents in a Matrix. Ok I suppose I'll go all the way with it. We are doing the first part of a page ranking algorithm (adapted for our level I suppose).
We have two matrices. The first one stores the contest of the text file. The second reads a web page from a first matrix then opens the web page found on the coresponding line and then searches it for links towards other web pages. What I don't know how to do is to read web page's address from the first matrix.

Ex: let's say I have "mysite.com" stored on the Store[i][] line in my Store matrix. I want to use "mysite.com" as a reading source for my getline() function. The only problem is that they only showed us how to stream contents from a file but not from a vector or a matrix.
The mechanics of downloading using HTTP is straight forward. You can do it yourself, or there are a few libraries kicking around that'll do it.
curl is a common Linux one
fetch is BSD one
Umm didn't get you at all. Here's what I'mtrying to do:

Let's say I have a text.txt that looks like this

1
2
3
4
link.html
...
...
link2.html
etc.

Now I do:

file.open("text.txt");
file.getline(link,100);

after this I get the contents of the text.txt into a matrix so i'll have something like this.

*0 1 2 3 4 5. . . .
0 l i n k . h t m l
1
2
3
etc etc.

now after I'm done filling my matrix I want to start using the matrice's lines as a source for getline.

So I tried
1
2
file.open(v[i]);
file.getline(link2,100);


But nothing happens. It seems like it isn't opening anything in v[i] when it should be opening link.html (if my i=0 for example).
Last edited on
I think I'm lost too. I'm not clear on what you mean by matrix. Do you mean an array of strings?

In your example, file.open(v[i]);, what is value does v[i] have?
I imagine v is a matrix, and v[i] gets the i-th string in it. If this is right, then you need to use c_str() to get a C-style string. I'm pretty sure opening a file requires it.
Last edited on
Topic archived. No new replies allowed.