Read .txt into String

Pages: 12
Starts at --> 5654
Ends at --> 5689
The Title is: title=Stop+Motion+Animation+Drawing


You're code cannot find "title". That is why your Starts at number is that big. That number is the maximum a string can hold I believe. I forgot.

The position of the first occurrence in the string of the searched content.
If the content is not found, the member value npos is returned.


Maximum value for size_t
npos is a static member constant value with the greatest possible value for an element of type size_t.

This value, when used as the value for a count parameter n in string's member functions, roughly indicates "as many as possible".

When used in some pos parameters that allow for out-of-range values, npos indicates the end of the string.

As a return value it is usually used to indicate failure.

This constant is actually defined with a value of -1 (for any trait), which because size_t is an unsigned integral type, becomes the largest possible representable value for this type.
Last edited on
Like I said. It could be your IDE, your compiler, or how you set up your file directory. I don't really know at this point.
Okay, here is the complete Code. Is there anything that could be the problem? Cause I still dont get what i want..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <fstream>

int VideoIndex = 1;

int main (int argc, const char * argv[])
{

    using namespace std;
    
    string links;
    string current;
    string Realname;
    
    system("clear");
    cout << "Enter Path to Youtube Link List: ";
    
    if(!(cin >> links)) {
        cout << "\nError while loading Path!\n";
        return 1;
    }
    
    ifstream f;
    ifstream f2;
    f.open(links.c_str(), ios::in);
    
    while(getline(f, current)) { //f muss noch geschlossen werden!!!!!!!!!
        //Wenn noch weitere links in der Datei sind
        //Lese diese ein, wenn nicht --> exit
        
        //Begin der Youtube-ID finden
        
        unsigned int found;
        unsigned int lenght;
        found = current.find("=");
        found++;
        found++;
        lenght = current.length();
        
        //ID "Auschneiden"
        
        if (lenght > 42) {
            //Längere id
            string ytid = current.substr(31, 58);
            cout << "Video ID of Video " << VideoIndex << " is: " << ytid;
            cout << "\nFetching info Data from Youtube...\n";
            //Building Link
            string videoinfo = "http://www.youtube.com/get_video_info?video_id=" + ytid;
            cout << "Downloading info from --> " << videoinfo << "\n";
            //Downloading info File
            string command = "wget -q -O /tmp/get_video_info " + videoinfo;
            system(command.c_str());
            system("sleep 3");
            cout << "Searching for Informations...\n";
            
            //Namen finden
            
            string name;
            system("chmod 777 /tmp/get_video_info");
            f2.open("/tmp/get_video_info", ios::in);
            cout << f2.good() << endl;
            cout << "Opening File...\n";
            while(getline(f2,name)) {
                cout << name << endl;
            }
            if(name.find("title")){
                unsigned int beginn = name.find("title");
                unsigned int ende = name.length();
                cout << "Starts at --> " << beginn << endl;
                cout << "Ends at --> " << ende << endl;
            }
            else{
                cout << "Something verry strange happened...\n";
                return 1;
            }
            
        }
    }
    
    
    return 0;
}


When I debug the Programm with gdb, all is good and the result is fine, but when i run it in terminal, it will not work..

EDID: Got it to work, thanks to all of you, dont know what was the problem but now it works just fine :)
Last edited on
Worked for me.
Enter Path to Youtube Link List: text
Video ID of Video 1 is: oded_fmt_stream_map=url%3Dhttp%253A%252F%252Fo-o.preferr
ed
Fetching info Data from Youtube...
Downloading info from --> http://www.youtube.com/get_video_info?video_id=oded_fm
t_stream_map=url%3Dhttp%253A%252F%252Fo-o.preferred
Searching for Informations...
0
Opening File...
Starts at --> 4294967295
Ends at --> 0


If it doesn't work in your terminal, its because using an IDE and using an actual terminal is not the same thing. Your paths could be off.

Now. Let me see why it isn't finding title.. Is it supposed to find title?





Oh. Nevermind. 0 means the file isn't found. Lol. Silly me.
Last edited on
Ok. I changed "/tmp/get_video_info" to links.c_str() and everything worked fine.
Okay now my Problem is to remove the '+' out of the title.

I tryed

1
2
3
4
5
6
If(RealTitle.find("+")){
while(RealTitle.find("+")){
unsigned int beginnplus = RealTitle.find("+");
RealTitle.erase(beginnplus,beginnplus+1);
}
}


But how could I replace all '+' with " "? And that code did not worked for me, or is that a problem with the IDE?

Im using XCode 4.
Hmm.. instead of using erase, use replace.

str.replace(beginnplus, 1, " ");

Try that, I don't know if it will work.

Also. "If" should be "if" and what is RealTitle? Did you make that a string?
Replace

1
2
3
4
5
6
If(RealTitle.find("+")){
while(RealTitle.find("+")){
unsigned int beginnplus = RealTitle.find("+");
RealTitle.erase(beginnplus,beginnplus+1);
}
}


with

1
2
3
4
5
6
7
8
9
string RealTitle = name.substr ( beginn + 6, ende );
for ( unsigned int index = 0; index < RealTitle.length ( ); index++ )
{
    if ( RealTitle[index] == '+' )
    {
        RealTitle[index] = ' ';
    }
}
cout << endl << "The title is: " << RealTitle << endl << endl;


As you can see. I created the RealTitle string for you. It only includes the title with + signs.
The for loop goes through and replaces the + signs with spaces.
Last edited on
Thank you:) i will try that when im at home.
Topic archived. No new replies allowed.
Pages: 12