Click to See Complete Forum and Search --> : files
nabeels786
May 31st, 2002, 05:52 PM
heres what i want to do
read in a file, read in each line, if the line contains something, then modfy that line, save the text file
the thing i dont get it that i have to specify a length to read in, i dont know the length for each line, help?
thanks :)
nabeels786
May 31st, 2002, 09:09 PM
i get errors
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\C++\php_format\php_format.cpp(52): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'ifstream'
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\C++\php_format\php_format.cpp(44): error C2872: 'ifstream' : ambiguous symbol
bah?
ifstream ifile;
ifile.open(argv[1]);
if(!ifile){
printf("Could not open file, or file does not exist!\n");
return exit();
}
while(getline(ifile, sTmp))
{
//validate stuff in here
printf("%s\n", sTmp.c_str());
printf("%c",istag(sTmp.c_str());
//sFile += sTmp + '\n';
}
istag() is a seperate function i wrote
nabeels786
May 31st, 2002, 09:16 PM
hmm
when i do
while(getline(ifile, sTmp))
it says "2 arguments specified, 3 needed"
while(getline(ifile, sTmp, '\n'))
it says "3 arguments specified, 2 needed"
:confused:
nabeels786
May 31st, 2002, 09:19 PM
ok fixed the other errors
what does "error C2872: 'ifstream' : ambiguous symbol
" mean?
parksie
Jun 1st, 2002, 03:18 AM
Did you include <fstream> ?
nabeels786
Jun 1st, 2002, 09:46 AM
yup.
im using vc7 if that helps
SteveCRM
Jun 1st, 2002, 10:16 AM
if you have #include <fstream> you'll need
using namespace std;
otherwise you'll have to use fstream.h
I've always used .h, works for me
don't know how much help this is but, :cool:
nabeels786
Jun 1st, 2002, 10:17 AM
i tried both, no go
SteveCRM
Jun 1st, 2002, 10:18 AM
can you post the whole source if its not that long? so I can put it in VC++ and try to get it
nabeels786
Jun 1st, 2002, 10:23 AM
ifstream ifile; //file stream var
ifile.open(argv[1]);
if(!ifile){
printf("Could not open file, or file does not exist!\n");
return exit();
}
sFile="";
while(ifile.getline(input,255,'\n') && !ifile.eof()) {
debug(input); //DEBUG
if(istag(input)=='h'){ //its an HTML tag
sTmp = "<?";
strreplace(input,"\"","\\\""); //replace " and ' with \" and \'
sTmp += input;
sTmp += "?>";
}
sFile+=sTmp + '\n';
}
SteveCRM
Jun 1st, 2002, 10:43 AM
the problem is on this line
strreplace(input,""","\\""); //replace " and ' with \" and '
you can't say " " ", it thinks the second one is ending the string. To make it ignore any character, put \ in front of it, so """ can now be "\"", this will make a quote in the string:)
nabeels786
Jun 1st, 2002, 10:49 AM
the php formatting thing took it out. i have the backslash there though.
it says the error is in ifstream ifile.
heres that whole if:
if(istag(input)=='h'){ //its an HTML tag
sTmp = "<? echo \"";
strreplace(input,"\"","\\\""); //replace " and ' with \" and \'
sTmp += input;
sTmp += "\" ?>";
}
parksie
Jun 1st, 2002, 10:51 AM
Originally posted by SteveCRM
if you have #include <fstream> you'll need
using namespace std;
otherwise you'll have to use fstream.h
I've always used .h, works for me
don't know how much help this is but, :cool: Should always use <fstream>, .h won't work at all very soon (just try using it with VC7, it complains bitterly :D
SteveCRM
Jun 1st, 2002, 10:55 AM
noooooooooooooo hehe gotta start using that :)
oh maybe this then?
you need to set what file
ifstream ifile(yourfile, opentype);
most popular open types are ios::trunc, ios::app (truncate, and append)
:)
nabeels786
Jun 1st, 2002, 10:58 AM
alright, i did clean buld, and rebuilt it, now it doesnt complain about that
now its
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\C++\php_format\php_format.cpp(68): error C2001: newline in constant
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\C++\php_format\php_format.cpp(68): error C2015: too many characters in constant
c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\C++\php_format\php_format.cpp(68): error C2146: syntax error : missing ')' before identifier 'and'
parksie
Jun 2nd, 2002, 04:40 AM
You've got some mismatched quotes/backslashes somewhere, I think.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.