CIN mit Leerzeichen



  • Ich habe einen char mit max 512 Zeichen.
    Mit cin >> txt; wird die Eingabe in txt gespeichert.
    Doch wenn man einen String mit Leerzeichen eingibt wird die nächste Eingabe übersprungen. Gibt es da ne andere Methode um eine Eingabe in einen String zu speichern?



  • // Copyright 2009 by 
    // Version 1.2.0
    
    #include "stdafx.h"
    #include "iostream"
    #include "string"
    
    using namespace std;
    
    int main()
    {
    char ip[512];
    string txt;
    char msg[512];
    int anz;
    int anz2 = 0;
    cout << "Bitte gebe die IP Adresse ein:" << endl;
    cin >> ip;
    cout << "Gebe eine Nachricht ein:" << endl;
    cin.get(txt);
    cout << "Wie oft soll die Nachricht gesendet werden?" << endl;
    cin >> anz;
    sprintf(msg,"net send %s \"%s\"",ip,txt);
    point:
    if(anz2 == anz)
    {
    } else {
    anz2 += 1;
    system(msg);
    goto point;
    cout << "error";
    }
    cout << endl << "Copyright 2009 by Lennard K." << endl;
    system("pause");
    return 0;
    }
    

    Da der Code.



  • Sorry, das ist der richtige:

    // Copyright 2009 
    // Version 1.2.0
    
    #include "stdafx.h"
    #include "iostream"
    #include "string"
    
    using namespace std;
    
    int main()
    {
    char ip[512];
    char txt[512];
    char msg[512];
    int anz;
    int anz2 = 0;
    cout << "Bitte gebe die IP Adresse ein:" << endl;
    cin >> ip;
    cout << "Gebe eine Nachricht ein:" << endl;
    cin >> txt;
    cout << "Wie oft soll die Nachricht gesendet werden?" << endl;
    cin >> anz;
    sprintf(msg,"net send %s \"%s\"",ip,txt);
    point:
    if(anz2 == anz)
    {
    } else {
    anz2 += 1;
    system(msg);
    goto point;
    cout << "error";
    }
    cout << endl << "Copyright 2009 by Lennard K." << endl;
    system("pause");
    return 0;
    }
    

Anmelden zum Antworten