[Solved] C++ does not name a type error in Codeblocks [duplicate]


You can’t put arbitrary statements at the file scope in C++, you need to put them in a function.

#include <string>
#include <fstream>
#include <streambuf>
#include <sstream>

int main () {
    //These are now local variables
    std::ifstream t("C:/Windows/System32/drivers/etc/hosts-backup.txt");
    std::stringstream buffer;

    //We can write expression statements because we're in a function
    buffer << t.rdbuf();
}

4

solved C++ does not name a type error in Codeblocks [duplicate]