need help !!
-
hi i am kind of new in programming and am still learning c++ , and so far i know about functions arrays pointers and a little about file processing but no knowledge of object and classes... anyway , i've been encountering some annoying problems , and i found out that they're all about the difference between the .h header files and the new ones with the 'using' and namespaces. and here's some of the problems i found : - when i use and for example i store 025 in an integer with cin and then output it with cout i'll get a different value but with and using namespace std; i dont have this problem - while outouting and inputing to a file with and using namespace std; and then passing this file to a recursive function as follows : void func ( ifstream dd ) { ..bla bla func(dd) bla bla.. } ... ifstream file ("ff.txt"); func (file); ... I get errors but with i dont get these kind of errors So if anybody would explain to me (in a simplified way) why i get these errors and if there's a way to do the same job with the new header files cause as you know in early courses they dont explain such things And thanks ==<< ormax3 >>==
-
hi i am kind of new in programming and am still learning c++ , and so far i know about functions arrays pointers and a little about file processing but no knowledge of object and classes... anyway , i've been encountering some annoying problems , and i found out that they're all about the difference between the .h header files and the new ones with the 'using' and namespaces. and here's some of the problems i found : - when i use and for example i store 025 in an integer with cin and then output it with cout i'll get a different value but with and using namespace std; i dont have this problem - while outouting and inputing to a file with and using namespace std; and then passing this file to a recursive function as follows : void func ( ifstream dd ) { ..bla bla func(dd) bla bla.. } ... ifstream file ("ff.txt"); func (file); ... I get errors but with i dont get these kind of errors So if anybody would explain to me (in a simplified way) why i get these errors and if there's a way to do the same job with the new header files cause as you know in early courses they dont explain such things And thanks ==<< ormax3 >>==
#include using namespace std; // cout << [wide range of types] << [wide range of types] << endl; char a = 'a'; int b = 38273; double c = 9382; char * d = "hello"; cout << a << " " << b << " " << c << d << endl;
---------------------------------------------------------------------------#include "stdafx.h" #include #include using namespace std; int main(int argc, _TCHAR* argv[]) { char * OurBuffer = new char[2048]; FILE * FileHandle; ///////////////////////////////////////////////////////////// cout << "Reading from C:\\BOOT.INI, using a " << ( sizeof(char) * 2048 ) << " byte buffer." << endl; ///////////////////////////////////////////////////////////// cout << "Now displaying the file as it is read line by line." << endl; ///////////////////////////////////////////////////////////// ///// EXAMPLE: FileHandle = fopen( "C:\\mydir\\myfile.txt", "r" ) FileHandle = fopen( "c:\\boot.ini", "r" ); while( OurBuffer[0] != 0 ) { ///////////////////////////////////////////////////////////// OurBuffer[0] = 0; fgets( OurBuffer, 2048 * sizeof(char), FileHandle ); cout << OurBuffer; ///////////////////////////////////////////////////////////// } ///////////////////////////////////////////////////////////// return 0; }
---------------------------------------------------------------------------Get a string from a stream. char *fgets( char *string, int n, FILE *stream ); wchar_t *fgetws( wchar_t *string, int n, FILE *stream ); Parameters string Storage location for data. n Maximum number of characters to read. stream Pointer to FILE structure. Return Value Each of these functions returns string. NULL is returned to indicate an error or an end-of-file condition. Use feof or ferror to determine whether an error occurred.
---------------------------------------------------------------------------Open a file. FILE *fopen( const char *filename, const char *mode ); FILE *_wfopen( const wchar_t *filename, const wchar_t *mode ); Parameters filename Filename. mode Type of access permitted. Return Value Each of these functions returns a pointer to the open file. A null pointer value indicates an error. ----------------------------------------------------------------------------------------