Problem mit den manipulatoren



  • QQ es will nicht funktionieren ...

    vector<char>var(40);
    vector<char>var2(40);
    ifstream f ( "test.txt");
    ifstream f2 ("test2.txt");
    
    ofstream file ("final.txt");
    
    while(  f.getline(&var[0],40) && f2.getline(&var2[0],40)   )
    {
    file << &var[0]<< setw(15) << &var2[0] << "\n";
    }
    

    Inhalt von test.txt
    name
    nachname

    Inhalt von test2.txt
    abcdef
    ghi

    final.txt
    name abcdef
    nachname ghi

    Ich will aber das die final.txt so aussieht:
    name abcdef
    nachname ghi

    Was mach ich da falsch? 😡


  • Mod

    #include <iostream>
    #include <iomanip>
    
    int main()
    {
      char vorname[]="Hans";
      char nachname[]="Meier";
      std::cout << std::left << std::setw(15) << "Vorname: " << vorname << '\n' 
                << std::setw(15) << "Nachname: " << nachname << '\n';
    }
    

    P.S.: std::string?


Anmelden zum Antworten