Find unter Linux anders ?



  • Hallo,
    ich habe ein kleines Problem und zwar warum Funktioniert dieser Code nur unter Windows ?

    if(strRecv.find("PING :") == 0) {
    
        string sMsg = "PONG " + strRecv.substr(strRecv.find(":")) + "\n";
        send(sockfd, sMsg.c_str(), sMsg.size(), 0);
    
    }
    

    Versuche ich diesen Code unter Linxu lässt es sich zawr kompilieren aber PONG sendet er nicht 😞 Wobei das unter Windows prima klappt daher die Frage ist unter Linux mit find etwas zu beachten 😕
    Hoffe ihr versteht was ich meine und könnt mir helfen

    Gruß



  • ist bestimmt zufall, dass das unter windoof funzt. schau dir mal den rückagbewert von 'send' an



  • Hallo,
    selbst wenn ich einen Text mit cout ausgebe erscheint er nicht 😕
    Liegt also irgendwie an der IF abfrage ich weiss nur nicht woran genau vielleicht fällt euch ja noch was auf 😞

    Gruß



  • Dummie schrieb:

    Hallo,
    selbst wenn ich einen Text mit cout ausgebe erscheint er nicht 😕
    Liegt also irgendwie an der IF abfrage ich weiss nur nicht woran genau vielleicht fällt euch ja noch was auf 😞

    Gruß

    Gib dir vor der if abfrage strRecv und strRecv.find("PING :") mal aus.



  • Ich habe nun die ganze Zeit ausprobiert...
    Und der Fehler lag wie ich vermutet hatte in der IF
    if(strRecv.find("PING :") == 0) ist falsch es muss != 0 heissen zumindestens eght es anscheinen so bei mir habe es aber erst vor 20 Sekunden rausgefunden und muss das noch austesten 😉

    Gruß



  • find

    Syntax:

    size_type find( const string& str, size_type index );
    size_type find( const char* str, size_type index );
    size_type find( const char* str, size_type index, size_type length );
    size_type find( char ch, size_type index );

    The function find() either:

    returns the first occurrence of str within the current string, starting at index, string::npos if nothing is found,
    returns the first occurrence of str within the current string and within length characters, starting at index, string::npos if nothing is found,
    or returns the index of the first occurrence ch within the current string, starting at index, string::npos if nothing is found.

    For example:

    string str1( "Alpha Beta Gamma Delta" );
    unsigned int loc = str1.find( "Omega", 0 );
    if( loc != string::npos )
    cout << "Found Omega at " << loc << endl;
    else
    cout << "Didn't find Omega" << endl;

    🙄


Anmelden zum Antworten