-
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 :)
-
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;
}
-
-
>that didnt work
..and that doesn't help much. How didn't it work?
-
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.
-
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.
-
The warnings show that you're using string.h which doesn't support the C++ string class, use <string>, not <string.h>.
-Prelude