|
-
September 25th, 2002, 04:55 AM
#1
stupid question about arrays
if i have an array such as:
unsigned short m_usArray[1000];
and i fill it up with unsigned shorts, is there away i can write the entire array to a file with just one command instead of doing something like:
ofstream ("file.txt");
for( int i = 0; i < 1000; i++ )
{
fout << m_usArray[i];
}
fout.close();
?
cheers, bigdaz
-
September 25th, 2002, 06:31 AM
#2
Code:
#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;
const unsigned int SIZE = 10;
int main(int argc, char *argv[])
{
unsigned short numberList[SIZE] = {1,2,3,4,5,6,7,8,9,10};
copy(numberList, numberList + SIZE, ostream_iterator<unsigned short>(cout, "\n"));
return (0);
}
-
September 25th, 2002, 06:32 AM
#3
Re: stupid question about arrays
Hi,
to answer your question, maybe :-) If there were a command
out there, please tell me how you would want it to look.
My guess would be:
WriteArrayToFile(char *FileName, int Options, USHORT *pusArray, int Length);
It is quite possible it does exist, or if not, someone could make
it for you.
Dave
Originally posted by BigDaz
if i have an array such as:
unsigned short m_usArray[1000];
and i fill it up with unsigned shorts, is there away i can write the entire array to a file with just one command instead of doing something like:
ofstream ("file.txt");
for( int i = 0; i < 1000; i++ )
{
fout << m_usArray[i];
}
fout.close();
?
cheers, bigdaz
-
September 25th, 2002, 06:35 AM
#4
I'm sorry; this example actually uses a file like you wanted in the
first place:
Code:
#include <algorithm>
#include <iostream>
#include <iterator>
#include <fstream>
using namespace std;
const unsigned int SIZE = 10;
int main(int argc, char *argv[])
{
ofstream of("file.txt");
unsigned short numberList[SIZE] = {1,2,3,4,5,6,7,8,9,10};
copy(numberList, numberList + SIZE, ostream_iterator<unsigned short>(of, "\n"));
return (0);
}
-
September 25th, 2002, 09:57 AM
#5
ok that worked a treat, thanks.
cheers, bigdaz.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|