C++ C++;:标准::ifstream ifs(路径)和#x27;路径应该是一个常量';
我想让这样的东西起作用:C++ C++;:标准::ifstream ifs(路径)和#x27;路径应该是一个常量';,c++,fstream,C++,Fstream,我想让这样的东西起作用: #include <iostream> #include <fstream> #include <string> std::string path; char c; while (true) { cin >> path; std::ifstream ifs(path); c = ifs.get(); while (ifs.good()) { cout << c &
#include <iostream>
#include <fstream>
#include <string>
std::string path;
char c;
while (true) {
cin >> path;
std::ifstream ifs(path);
c = ifs.get();
while (ifs.good()) {
cout << c << endl;
c = ifs.get();
}
cout << endl;
}
#包括
#包括
#包括
std::字符串路径;
字符c;
while(true){
cin>>路径;
std::ifstream ifs(路径);
c=ifs.get();
而(ifs.good()){
你有两个选择(我知道):
使用c++11(添加std=c++11编译标志)
使用std::ifstream ifs(path.c_str())
更改std::ifstream ifs(path)
你有两个选择(我知道):
使用c++11(添加std=c++11编译标志)
使用std::ifstream ifs(path.c_str())
更改std::ifstream ifs(path)
至于C++ 11,这是不必要的。但是,Nick可能不使用C++ 11,否则他不会得到这样的错误。我已经添加了C++ 11选项。我使用Visual C++ +2010作为C++ 11。这是不必要的。我不知道。但是,Nick可能不使用C++ 11,否则他不会得到这样的错误。我已经添加了C++ 11选项。我使用Visual C++ 2010