Results 1 to 16 of 16

Thread: files

  1. #1

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919

    files

    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
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  2. #2

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    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?


    PHP Code:
    ifstream ifile
        
    ifile.open(argv[1]);

        if(!
    ifile){
            
    printf("Could not open file, or file does not exist!\n");
            return exit();
        }

        while(
    getline(ifilesTmp))
        {
            
    //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
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  3. #3

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    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"


    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  4. #4

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    ok fixed the other errors

    what does "error C2872: 'ifstream' : ambiguous symbol
    " mean?
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Did you include <fstream> ?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    yup.

    im using vc7 if that helps
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    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,

  8. #8

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    i tried both, no go
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  9. #9
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    can you post the whole source if its not that long? so I can put it in VC++ and try to get it

  10. #10

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    PHP Code:
    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';
        }
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  11. #11
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    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

  12. #12

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    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 += "\" ?>";
    }
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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,
    Should always use <fstream>, .h won't work at all very soon (just try using it with VC7, it complains bitterly
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    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)

  15. #15

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    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'
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You've got some mismatched quotes/backslashes somewhere, I think.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width