| | |
Open variable named files
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
hello,,
i need help on how to open files by using variable names..
here's my function:
my problem is that there's always an error on the file.open line...
"no matching function to call...etc"
this is where i call the function in my main:
sorry if you don't understand it,,
thx for helps... i need this asap btw,,
i need help on how to open files by using variable names..
here's my function:
•
•
•
•
void stringSearcher(string filename, string search) { ifstream file; file.open(filename); if(!file.is_open()) { cerr<<"File can't be open..."<<endl; exit(1); } string line; while(!file.eof()) { getline(file, line); if(line.find(search)==0) { displayTitle(line); exit(1); } } }
"no matching function to call...etc"
this is where i call the function in my main:
•
•
•
•
while (pent=readdir(pdir)) { if (checkXML(pent->d_name)) { list.push_back(pent->d_name); string title("<TITLE>"); stringSearcher(pent->d_name, title); } }
thx for helps... i need this asap btw,,
Last edited by azwraith69; Jan 24th, 2009 at 10:47 pm.
I am living in a mere program...
When you see it say that there's "no matching function", that means there's no function with the given name that expects the types you've provided. If you double-check the documentation for ifstream's open function, you'll see that it takes a char*, not a string.
So use the .c_str() member function to get a char*.
So use the .c_str() member function to get a char*.
•
•
•
•
When you see it say that there's "no matching function", that means there's no function with the given name that expects the types you've provided. If you double-check the documentation for ifstream's open function, you'll see that it takes a char*, not a string.
So use the .c_str() member function to get a char*.
i have just did that.. now,, there's no more errors,,
but the problem is,, File can't be open...
•
•
•
•
void stringSearcher(string filename, string search) { ifstream file; ifstream openfile(filename.c_str()); if(!file.is_open()) { cerr<<"File can't be open..."<<endl; exit(1); } string line; while(!file.eof()) { getline(file, line); if(line.find(search)==0) { displayTitle(line); exit(1); } } }
and it is in the same directory with my source codes..
but it can't be open using .c_str()..
if i use file.open("file.xml"),, it opens properly....
what's the problem??
thx again,,
I am living in a mere program...
![]() |
Similar Threads
- How to configure GD (PHP)
- output based on serial port input (C#)
- Widget Event Handling (Python)
- create and write into INFO File from C# (C#)
- comparing file in c (C)
- file upload (JavaScript / DHTML / AJAX)
- Segmentation Fault (Core Dumped) (C++)
- ifstream ofstream Variable problem (C++)
- How do i run perl on windows 98 (Perl)
- RE: Leaked Windows Source Code (IT Professionals' Lounge)
Other Threads in the C++ Forum
- Previous Thread: I use Dev-C++ but...
- Next Thread: There are some missing functions? Can you help me please!
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






