【发布时间】:2014-11-22 09:33:34
【问题描述】:
我尝试使用 open() 打开与源文件位于同一目录中的 html 文件。但是我不知道为什么 is_open() 在我的程序中总是返回 false ...... 这是我的部分源代码
readHTML.cpp中打开html文件的函数之一
#include "web.h"
...
void extractAllAnchorTags(const char* webAddress, char**& anchorTags, int& numOfAnchorTags)
{
ifstream myfile;
char line[256];
char content[2048] = "";
numOfAnchorTags = 0;
myfile.open(webAddress);
cout<< myfile.is_open()<<endl;
if (myfile.is_open())
{......}
}
头文件,web.h
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
struct WebNode
{
char* webAddress;
char* anchorText;
WebNode** hyperlink;
int numOfHyperlinks;
};
void extractAllAnchorTags(const char* webAddress, char**& anchorTags, int& numOfAnchorTags);
另一个cpp文件,调用F.cpp
#include "web.h"
........
WebNode* createWeb(const char* webAddress, const char* anchorText, int height)
{
if(height != 0){
WebNode* webNode = new WebNode;
char** anchorTags;
int numOfAnchorTags;
strcpy(webNode->webAddress,webAddress);
strcpy(webNode->anchorText,anchorText);
extractAllAnchorTags(webAddress,anchorTags,numOfAnchorTags);
\*.........................*\
}
.......
main.cpp
#include "web.h"
int main(){
.............
cin >> filename; // index.html would be input during running.
Page = createWeb(filename, anchorText, max_height);
.............
}
我的 main.cpp 只需调用一次 createWeb 但是我得到的 myfile.is_open() 总是返回 false,因为它在我的 Eclipse 控制台中打印出 0 ... 我不知道为什么我什至尝试将我的参数目录重置为我的工作区 或者我将我的 html 文件放在调试文件夹中.. 它仍然返回 false。
【问题讨论】:
-
哪个操作系统?
-
我使用的是 Windows 7 64 位