String in c++ modul



  • Hallo

    Folgendes Problem. Versuche in einer Moduldatei einen String zu definieren. Funktioniert aber nicht

    hab mal ein kleines Programm geschrieben

    //main.cpp
    #include <cstdlib>
    #include <iostream>
    #include <string>
    using namespace std;
    #include "modul.h"
    using namespace test;
    
    int main(int argc, char *argv[])
    {
    vers();
    
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
    //modul.cpp
    #include <string>
    namespace test
    { 
       string temp = "hallo";           
        void vers(void)
        {
        cout << temp<<endl;     
        }          
    }
    
    //modul.h
    namespace test
    {
     void vers (void);
    }
    

    Beim Kompilieren bringt er folgenden fehler

    `string' does not name a type



  • Du musst auch std::string per using oder using namespace in den Namensraum test einbinden oder es direkt voll qualifizieren.



  • //modul.cpp
    #include <string>
    #include <iostream>
    using namespace std; 
    namespace test
    { 
    
       string temp = "hallo";           
        void vers(void)
        {
        cout << temp<<endl;     
        }          
    }
    

    habs jetzt mal so gemacht funktioniert, hoffe es war das was gemeint war.

    Vielen dank für die schnelle Hilfe


Anmelden zum Antworten