|
ios::nocreate and ios::noreplace are very pre standard C++, they were too platform specific and never made it into the new standard. You will find them in the old <fstream.h> headers as opposed to your <fstream> header. Your out of luck, try validating the file yourself.
fstream fs(“fname”, ios_base::in);// attempt open for read
if (!fs)
{
// file doesn't exist; don't create a new one
}
else //ok, file exists. close and reopen in write mode
{
fs.close();
fs.open(“fname”, ios_base::out); // reopen for write
}
-- modified at 13:59 Sunday 20th August, 2006
|
|
|
|
|
What's wrong with ios::nocreate? I am getting these errors in VS2003:
SentenceList.cpp(23): error C2039: 'nocreate' : is not a member of 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
SentenceList.cpp(23): error C2065: 'nocreate' : undeclared identifier
Code:
void CSentenceList::readFile(char strFileToRead[MAX_FILENAME_LENGTH])
{
char strLine[MAX_SENTENCE_LENGTH + 1];
fstream fileToRead(strFileToRead,ios::nocreate);
while (!fileToRead.eof() && Size < MAX_LINES)
// Read line of text from file and update Sentences.strSentence.
{ fileToRead.getline(strLine, MAX_SENTENCE_LENGTH);
Sentences.Insert(strdup(strLine));
Size++;
}
fileToRead.close();
}
Jon
|
|
|
|
|
Are you dynamically linking to the header file?
|
|
|
|
|
I have included fstream...
#include <fstream>
Jon
|
|
|
|
|
try:
#include<fstream.h>
I have had ios::nocreate work with the .h include statement, but I haven't had anything work with just the fstream include statement.
|
|
|
|
|
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
ostream& curren(ostream &s, int fieldSize)
{
cout << "$";
cout.setf(ios.fixed | ios::showpoint);
cout.precision(2);
cout.width(fieldSize);
return s;
}
// was this deprecated??
omanip (int) currency (int fieldSize);
{
return omanip<int>(curren,fieldSize);
}
void main ()
{
double someMoney = 13.5678;
cout<<currency(7)<<someMoney<<endl;
}
Jon
|
|
|
|
|
|
Actually it seems Microsoft left it out from omanip that comes bundled with VS2003, however it seems to be available on Borland (which I don't have).
Thanks for your help.
Jon
|
|
|
|
|
Help me to figure out, how can i control windows explorer with my program ?. For example i want to make program if i click button "back" in my program, it command windows explorer to back, if i click button "up", it command windows explorer to going up from current directory. is this possible to make ???? please help me
Sory about my english, like you guess english not my mother language
|
|
|
|
|
You might want to start of by using a spy utility like SPY++ to find out what commands and such are sent when buttons are pressed. If you can find that out it should be a simple task as sending the window a message )
|
|
|
|
|
i create a thread and got the Handle.
how can i get the following information of the thread?
1. is the thread object signaled? when can it be signaled?
2. is the thread suspended? it is easy but how to get the suspend count?
3. has the thread terminated? what happens to the thread object if the thread funtion quits? reset to NULL?
i looked up the google but could not get clear answer, wish you guys here can help me out, thanks alot!
|
|
|
|
|
A thread object is signaled when the thread exits. Call WaitForSingleObject() with a timeout of 0, and if it returns WAIT_OBJECT_0 then the object is signaled. The thread object in the kernel (like all such objects) remain around until all handles on them are closed.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
(2)Did you see SuspendThread(...) and ResumeThread(...)
|
|
|
|
|
The following error is being displayed when running this simple program:
stack around the variable 'values' was corrupted (same as subject)
#include <iostream>
#include <conio.h>
using namespace std;
void main ()
{
int x;
const int fieldSize = 10;
const int arraySize = 5;
double values[arraySize];
values[0] = 23.4;
for (x= 0; x < arraySize; x++)
values [x+1] = values[x] * .10;
for (x= 0; x < arraySize; x++)
{
cout.width(fieldSize);
cout<< values[x]<<endl;
}
cout.precision(2);
cout<<"After precision (2) call"<< endl;
for (x=0; x < arraySize; x++)
{
cout.width(fieldSize);
cout<<values[x]<<endl;
//error is displayed when arraySize = 5. The program seems to perform an extra loop.
}
}
Jon
|
|
|
|
|
|
|
const int arraySize = 5;
double values[arraySize];
values[0] = 23.4;
for (x = 0; x < arraySize; x++)
values [x+1] = values[x] * .10; Plug in x = 4 in the loop and you get:
values[5] = values[4] * .10; You're writing off the end of the array when you assign to values[5] .
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
that's right, sorry
Jon
|
|
|
|
|
I know its possible in C# using web resource provider but please tell me how to do it using VC++ .Is there any MFC available ???? i also want to login into that website using id and password. please reply
|
|
|
|
|
micku wrote: Is there any MFC available ????
Yes. Here's the MFC equivalent[^] of WebResourceProvider. You will likely want to pass the user id and password as post arguments.
/ravi
|
|
|
|
|
I have a toolbar and a statusbar on my main window, which I would like the user to be able to show or hide. Easy enough I know, but the problem is I have many controls on the dialog which would need to move as a result. I have coded it in a way that when ever a WM_SIZE message is processed, it calculates the rect for the toolbar and status bar. Calling the ShowWindow() function, does hide the controls, but GetClientRect() still return with the size. Is there a way around this? Non MFC by the way.
|
|
|
|
|
Can't you use SetWindowLong to show and hide one control?
you may need to use to the style using GetWindowLong function.
-- modified at 9:22 Sunday 20th August, 2006
|
|
|
|
|
Thanks for the suggestion. I used the SetWindowLong() function to disable the autosize feature of the toolbar, then resized it to 0, all seems to work, until I want to restore it. I reset the Styles, reset the size, and call for an update. The toolbar appears, minus the buttons??? I thought this would be a simple task so I left6 it till the last, guess I was wrong!
|
|
|
|
|
Currently i have a structure of
struct data
{
long int addNumber,addPostal,exMth,exYear;
char fName[40],lsName[40],addStreet[40],addCity[40],addState[40];
};
data dataRecords[100];
This is used to store values in dataRecords[0],dataRecords[1], etc...
In using this method, I can only store up to a max of 0-100 records. Is there anyway where number of dataRecords can be made dynamic? instead of limiting it to 100. There is another method of using linked list instead, but i dun have enuff time to change my whole program to adapt to it.
Thanks
|
|
|
|
|
The best way to deal with dynamic arrays is using the vector class from the standard template library.
Another way is yo use dynamic arrays (by using new[] and delete[]) but then you have to manage the memory yourself.
|
|
|
|