Problem mit Strings



  • #include <string> //ohne .h
    
    std::string test;
    
    //oder
    
    using namespace std;
    //...
    string test;
    


  • Also schön langsam bin ich etwas verzweifelt. in dem kleinen bsp programm
    funktioniert das jetzt zwar, aber wenn ichs in einem anderen projekt versuche ned.
    "std' : is not a class or namespace name"

    Weiters kann ich aus irgend einem grund auch das ".h" bei den headern ned
    weglassen (dann findet ers ned) obwohl ich ja mit vc++ code. liegts vielleicht an irgendwelchen einstellungen des compilers?

    es handelt sich um eine eigene cmd. hier mal der code, viel is ja noch ned: 😉

    #include <iostream.h>
    #include <stdio.h>
    #include <string.h>
    
    std::string command;
    
    int main()
    {
    
      char quellpfad[80],
           zielpfad[80],
           gescopy[80],
           source[80],
           aim[80];
    
      int  enterlock = 0;
    
        cout << "Welcome to my console" << endl << endl << "ws:>"; 
        cin >> command;
    
        while (command != "exit")
        {
            enterlock = 0;
            if (command == "copy")
            {
                enterlock = 1;
                cout << "Please enter the source path of the file." << endl << endl << "ws:>";
                cin >> source;
                cout << "Please enter the aim path." << endl << endl << "ws:>";
                cin >> aim;
    
                strcpy(quellpfad,"\"");
                strcat(quellpfad,source);
                strcat(quellpfad,"\"");
    
                strcpy(zielpfad,"\"");
                strcat(zielpfad,aim);
                strcat(zielpfad,"\"");
    
                strcpy(gescopy,"copy /y ");
                strcat(gescopy,quellpfad);
                strcat(gescopy," ");
                strcat(gescopy,zielpfad);
    
                system(gescopy);
    
                cout << endl << "ws:>";
                cin >> command;
            }
    
            if (command == "help")
            {
                cout << "'copy' - Copies a file to a location of your choice." << endl << "'exit' - Closes the aplication." << endl << endl << "ws:>";
                cin >> command;
            }
            else
            {
                if (enterlock == 0)
                {
                cout << "Bad command or file name." << endl << endl << "ws:>";
                cin >> command;
                }
            }
    
        }
    
      return 0;
    }
    

    liegts vielleicht an der position an der ichs deklarier?
    mfg Mindphreaker



  • mach ein

    #include <string>
    //anstelle deines
    #include <string.h>
    

    mfg



  • hmm, interessant. wenn ich bei

    #include <iostream.h>
    #include <stdio.h>
    

    das ".h" weglass findet er es nimmer.
    beim

    #include <string.h> scheints zu funktionieren.
    

    nur bekomm ich dann eine mörder fehlermeldung: 😉
    error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)

    also mit den fehlermeldungen von c komm ich irgendwie ned klar, werd einfach ned schlau aus ihnen. sorry, hat da wer ne idee?



  • Mindphreaker: Du mischst ja auch wild C und C++, was ist das denn für ein scheußliches Buch, das einem sowas vermittelt?


  • Mod

    vielleicht solltest du noch die version deines vc++ angeben...



  • ähm, ich weiß mitlerweile schon, dass man bei c++ kein ".h" nehem soll. aber bei meinem Vc++ gehts aus irgend einem grund ned anders. aus dem buch lern ich mitlerweile eh nimma. 🙂 .. aber vielleicht zurück zu meinem problem?



  • Naja, is ein bisschen kompliziert, weil Du unnötigerweise Funktionen aus <iostream>, <cstdio>, <string> _und_ <cstring> (bzw. <string.h) verwendest.

    Also: Wenn Du sonst keine Fehler drinhast, sollte Dein Programm so kompilieren:

    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    
    using namespace std;
    


  • wow, vielen dank für die hilfe! mit den headern funktionierts einfwandfrei. auch ohne ".h" aber woran lags jetzt eigentlich? habn sich da die header überschnitten oder wie?



  • Mindphreaker schrieb:

    habn sich da die header überschnitten oder wie?

    Nein, Du hast nur die falschen bzw. nicht genug eingebunden.


Anmelden zum Antworten