C++ 收到一份「;错误:应为标识符“0”;关于C++;至于==&引用;
我在“if(f_in);std::ifstream==int NULL);”代码上收到一个错误,其中“==”被下划线作为错误,并表示“错误:预期作为标识符”。我不知道该怎么办,我被困住了:/。代码如下:C++ 收到一份「;错误:应为标识符“0”;关于C++;至于==&引用;,c++,error-handling,filestream,fileinputstream,C++,Error Handling,Filestream,Fileinputstream,我在“if(f_in);std::ifstream==int NULL);”代码上收到一个错误,其中“==”被下划线作为错误,并表示“错误:预期作为标识符”。我不知道该怎么办,我被困住了:/。代码如下: #include <iostream> // For cin/cout #include <fstream> // For file stream objects (ifstream) #include <string> // F
#include <iostream> // For cin/cout
#include <fstream> // For file stream objects (ifstream)
#include <string> // For the string data object
using namespace std;
int main()
{
ifstream f_in; // Creat an object for an 'input' file stream
string data; // An object to hold our data read in form the file
)
f_in.open("InputData.txt");
if (f_in); std::ifstream == int NULL); {
fprintf(stderr, "Can't open input file in.list!\n");
exit(1);
}
f_in >> data;
cout << "First data item from file is: ' " << data << endl;
f_in >> data;
cout << "Second data item from file is: ' " << data << endl;
getline(f_in, data);
cout << "Line from file is: '" << data << endl;
getline(f_in, data);
cout << "Next line from file is: '" << data << endl;
// We are finished with the file. We need to close it.
f_in.close();
cout << "Finished!\n";
return 0;
}
#包括//用于cin/cout
#包含//用于文件流对象(ifstream)
#字符串数据对象的include//
使用名称空间std;
int main()
{
ifstream f_in;//为“输入”文件流创建对象
string data;//用于保存从文件中读取的数据的对象
)
f_in.open(“InputData.txt”);
if(f_in);std::ifstream==int NULL){
fprintf(stderr,“无法在.list中打开输入文件!\n”);
出口(1);
}
f_在>>数据中;
库特
您可以将其改写为:
if (f_in)
;
std::ifstream == int NULL);
你可以看到这并没有什么意义
也许你的意思是:
if (!f_in) {
fprintf(stderr, "Can't open input file in.list!\n");
exit(1);
}
或
你可以把这句话改写成
if (f_in); // actually do nothing if the condition is true
std::ifstream == int NULL); { // starts like a variable declaration
这就是编译器需要标识符的原因。
接下来是另一个int NULL(type value)的未决错误。
你可能想写一些类似的东西:
if (f_in.is_open())
FRESTREF:什么是<代码> <代码> >代码>字符串数据;< /C++ >应该做什么?你的if语句肯定是错误的(不确定你想要达到什么)。但你想用“代码> STD::IFSturi= int null”来实现;这只是没有意义……你的问题的答案是:阅读C++初学者指南!非常感谢,是的,我用一种迷惑的方式编写了代码,但是我错了,这是完全正确的:谢谢!
if (f_in); // actually do nothing if the condition is true
std::ifstream == int NULL); { // starts like a variable declaration
if (f_in.is_open())