Thread: how to make files

  1. #1
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36

    Exclamation how to make files

    How do I make my program make a file with information on it which i preset to put on the file....also is there way to make a blank text file or any type of file to the size I want...for example....like 5mbs? Maybe make a loop that keeps putting characters in a file and reaches 5mbs quits? Im just wondering really about the file size thing...but how do u make a file. Thanks in advance

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Something like this -

    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    
    int main()
    {
        string filename;
    
        cout << "Enter filename(with extension): ";
        cin >> filename;
    
        ofstream os(filename.c_str());
    
        int length;
        cout << "Enter required length(in MB): ";
        cin >> length;
    
        length*=1024*1024;
    
        while(length--)
        {
            os << 'a';
            if (length%2048==0)
                cout << '.';
        }
    
        return 0;
        
    
    }

  3. #3
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36
    that didnt work

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >that didnt work

    ..and that doesn't help much. How didn't it work?

  5. #5
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36
    When i complied I got these errors::
    Code:
    Info :Compiling G:\Encryption\test.cpp
    Warn :  string.h(549,3):Functions containing for are not expanded inline
    Warn :  string.h(557,3):Functions containing while are not expanded inline
    Warn :  string.h(563,3):Functions containing for are not expanded inline
    Warn :  string.h(575,3):Functions containing for are not expanded inline
    Warn :  string.cc(686,32):Comparing signed and unsigned values
    Warn :  string.cc(658,2):Cannot create pre-compiled header: code in header

    And when I ran it i got these errors::
    Code:
    Warning G:\BC5\INCLUDE\string.h 549: Functions containing for are not expanded i
    nline in template std::string_char_traits<charT>
    Warning G:\BC5\INCLUDE\string.h 557: Functions containing while are not expanded
     inline in template std::string_char_traits<charT>
    Warning G:\BC5\INCLUDE\string.h 563: Functions containing for are not expanded i
    nline in template std::string_char_traits<charT>
    Warning G:\BC5\INCLUDE\string.h 575: Functions containing for are not expanded i
    nline in template std::string_char_traits<charT>
    Turbo Link  Version 7.1.32.2. Copyright (c) 1987, 1996 Borland International
    Warning: Possible reference to undefined extern std::rwse_InvalidSizeParam in mo
    dule test.cpp
    Warning: Possible reference to undefined extern std::rwse_PosBeyondEndOfString i
    n module test.cpp
    Warning: Possible reference to undefined extern std::rwse_ResultLenInvalid in mo
    dule test.cpp
    Warning: Possible reference to undefined extern std::rwse_StringIndexOutOfRange
    in module test.cpp
    Warning: Possible reference to undefined extern std::rwse_UnexpectedNullPtr in m
    odule test.cpp
    Warning: Possible reference to undefined extern std::nullref in module test.cpp
    Warning: Possible reference to undefined extern std::__rw_stdexcept_NoNamedExcep
    tion in module test.cpp
    Error: Undefined symbol std::rwse_PosBeyondEndOfString in module test.cpp
    Error: Undefined symbol std::rwse_StringIndexOutOfRange in module test.cpp
    Error: Undefined symbol std::nullref in module test.cpp
    Error: Undefined symbol std::rwse_InvalidSizeParam in module test.cpp
    Error: Undefined symbol std::rwse_ResultLenInvalid in module test.cpp
    Error: Undefined symbol std::rwse_UnexpectedNullPtr in module test.cpp
    Error: Undefined symbol std::__rw_stdexcept_NoNamedException in module test.cpp
    The program does run but when after I enter the name of the file, I get an abnormal program termination.
    Last edited by quiksilver9531; 02-22-2002 at 05:45 PM.

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You could try changing

    string filename;

    to

    char filename[256];

    as the warnings seem to stem from the use of std::string. However, if you cannot use std::string with your compiler I'd seriously consider getting a different (newer) one.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    The warnings show that you're using string.h which doesn't support the C++ string class, use <string>, not <string.h>.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile producing a list of files.
    By leonm54 in forum Tech Board
    Replies: 1
    Last Post: 07-23-2007, 09:54 AM
  2. trying to make a KenGen ( for a game tool )
    By lonewolfy in forum C# Programming
    Replies: 4
    Last Post: 03-28-2007, 08:23 AM
  3. make variables visible on multiple files
    By jagerhans in forum C++ Programming
    Replies: 4
    Last Post: 08-28-2004, 06:32 PM
  4. "Cannot make pipe"
    By crepincdotcom in forum C Programming
    Replies: 5
    Last Post: 08-16-2004, 12:43 PM
  5. Help with Header/Make files
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 04-10-2002, 10:57 PM