'\o'

This is a discussion on '\o' within the C++ Programming forums, part of the General Programming Boards category; Don't you LOL me! When I think about it, I'll say thx to everybody who have even read what I've ...

  1. #16
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    Don't you LOL me! When I think about it, I'll say thx to everybody who have even read what I've typed since well... I'm Danish and doesn't really have greate english gramar skills. Besides that I hate looking for spelling errors.

    By the way would you plz post a reply with my code with those changes so that I'm sure I get it.
    Last edited by Zahl; 10-14-2002 at 11:38 AM.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  2. #17
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I dont have time to write my code so that it will fit as part of your class.....but here's a demo of a prog that loads a file, reads it and spews the contents to stdout....(text file only though - as I am displaying the contents, it wont work to well if you dont use a text file!!)...

    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    
    
    int main() {
    
    	std::cout << "Enter the name of the file" << std::endl;
    	std::string str;
    	std::getline(std::cin,str);
    	std::ifstream MyFile(str.c_str());
    	if(MyFile.is_open()){
    		int st,fin,sizefile;
    		st = MyFile.tellg();
    		MyFile.seekg (0, std::ios::end);
      		fin = MyFile.tellg();
      		sizefile = fin - st;
      		char *szstr = new char[sizefile + 1];
      		if(!szstr){
      			std::cout << "Error!" << std::endl;
      			return 1;
      		}
      		MyFile.seekg (0, std::ios::beg);
      		MyFile.read(szstr,sizefile);
      		szstr[sizefile] = '\0';  		
      		std::cout << szstr << std::endl;  		
      		delete [] szstr;
      	}
      	else std::cout << "Could not open file" << std::endl;
    
    
    	return 0;
    }

  3. #18
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    what is the following functions all about:
    tellg()
    seekg()
    and isn't read() maid for reading binary files.
    Further more I don't get why you write:
    "st = MyFile.tellg();" and "fin = MyFile.tellg();"
    That is, why do you get the same value two times or do it change and then how?

    -Edit-
    Why include both iostream and fstream
    Last edited by Zahl; 10-14-2002 at 01:19 PM.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  4. #19
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Sorry...didnt bother to comment...

    Code:
    st = MyFile.tellg();//get the position at the start
    MyFile.seekg (0, std::ios::end);//go to the end of the file
    fin = MyFile.tellg();//get the position at the end
    sizefile = fin - st;//end - start = size of file
    seekg goes to a position in the file relative to an offset......tellg gets that position

    The file position starts at 0....so if I go to the end of the file and get the position there, the difference between the start and the end will be the size...though looking at it, there was no need to take the start position as I had just created the file and it would have been zero.....ah well....

    Oh btw...I include both headers as I am using CodeWarrior, and that compiler wont compile this code without both headers....

  5. #20
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    Sorry that I bather you once more but since my help files doesn't have anything about those functions when I seach... what are the first parameter in seekg for.

    Funny... I thought you could only use read and write for binary files.
    Last edited by Zahl; 10-14-2002 at 03:39 PM.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  6. #21
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    its an offset......so if I do MyFile.seekg (10, std::ios::end);..its 10 from the end

  7. #22
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Try here

  8. #23
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    I gues that's another way of saying: Hey! Your like wasting my time and stuff! Now BUG off.

    Thx for all the help, and I can tell you that with all the final informartion you gave me the function run smoth like **** through a duck(or something else ).
    I've read the bog SAMS TEACH YOURSELF C++ IN 21 DAYS, so I thought I knew about those stream functions (described in chapter 17), but it seems it were only the first level. DOH! But as my signature says´, I'm working on it.
    Last edited by Zahl; 10-14-2002 at 03:49 PM.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21