Read the file line-by-line. Do not use eof() because it dosn't work the way you would think.
string line;
fstream in("filename",ios::in);
while( getline(in,line) )
{
// blabla
}
Read the file line-by-line. Do not use eof() because it dosn't work the way you would think.
string line;
fstream in("filename",ios::in);
while( getline(in,line) )
{
// blabla
}
FindFirstFile() and FindNextFile() works something like the dir DOS command. First call FindFirstFile, then if it returns a valid handle create a loop to call FindNextFile() until no more files are found. There are lots of examples for you to follow if you use google
And BTW you should just delete both lines 14 and 15 if you do the above.
There are win32 api functions that will search for all files and report back to the c program the file names. See FindFirstFile() and FindNextFile() at www.microsoft.com. If that's not what you want then I'm not certain what you mean. Yes your program could search for a specific file all over the hard drive and delete them all, but that would be very very time consuming. There again FindFirstFile() and FindNextFile() will do the job for you.
line 3: should be <fstream> (without the .h extension)
line 12: since on line 11 you used ifstream you can use ofstream for the output stream.
line 28: incorrect. should be this: sentence[i] = toupper(sentence[i]);
delete line 30 because it does nothing but confuse everything. I suspect what you are attempting to do is write the converted string to the output file. streamout << sentence << "\n";
is the file in the same director where the *.exe is located ? If not then your program can't delete it because the program doesn't know where to find it. And you don't have to use the system() function to delete a file -- just use remove() function.
Post a link in Website Reviews and people will help you out. Other than that, I have no idea how to help.
This is not a C proglem then, but an assembly language problem. But you should know that you can not use those interrupts with any modern 32-bit C or C++ compiler or create a DLL that contains them, or interface with any java program.
BTW: The subject of this thread is wrong -- there is no such thing as a C interrupt.
This is really an assembly language problem so I moved the thread from C to assmelby boards.
win32 api functions: FindFirstFile() and FindNextFile() will do that for you -- you don't have to resort to interrups. Here is a c++ way of doing that. BTW C++ is NOT required to use those functions
If you are using ancient MS-DOS compiler such as Turbo C or TurboC++ then obviously you can't use the above code snippet or functions. But dos.h contains _dos_findfirst() and _dos_findnext() . Again you don't have to use assembly interrupts.
8.59. And Windows Experience Index is 4.2.
Actually that snipped doesn't work at all for February not because of the syntax error but because we have to check for leap year in order to determine the maximum number of days in February.
Welcome to DaniWeb Bushido. I live just across the river near Belleville Illinois. Hope you can hang around a lot.
Also, your logic for checking valid day of month will fail to do its job
He's checking to see if the month has 31 days, so the || operator is appropriae there.
Must be old age creaping up on me for that mistake. :)
He's checking to see if the month has 31 days, so the || operator is appropriae there. However, IMO a switch statement would be more explicit
switch(month)
{
case 1: // January
case 3: // March
case 5: // May
case 7: // July
case 8: // August
case 10: // October
case 12: // december
// these months have 31 days
if( day > 0 && day < 32)
// the day is valid
break;
case 2: // February
// check the day
break;
default: // all the reset have 30 days
// check the day
break;
}
Note that there is no check for year in the above because the value of year is not related to any given month or day. Just check it once before or after the above switch statement.
variable NAV is used without ever being initialized or changed so it contains just some random value. You need to rethink what you want to do with that variable.
just do google search for odbc and you will find lots of examples. There is no such thing as a "simple" example because accessing databases is somewhat complex topic and there have been several books written about it. You will need to have a comfortable level of c or c++ knowledge to write database applications.
Is the advice different for devices that do not necessarily have an operating system.
Like embedded devices though?
Yes it would be different -- programs written for embedded devices without operating systems don't call exit() or return from main() because there is no place to return to. Embedded programming has a different set of standards then other ISO standards.
vijay: how would you connect that streambuf to a GUI edit control ? I don't understand the relevance of your code.
line 16: I don't know what compiler you are using but mine won't compile that line because arrays expects a const value. Maybe there is something new in C99 ? Most compilers will not like that line.
>>I get an infinite loop if my random number is 0
Yes because you can't have arrays of size 0 int array[0]
is not a valid array. Maybe add 1 to the rand % MAX value, then change MAX to 19 instead of 20 to avoid that problem.
You can write one GUI program that contains the edit box and reads the command-line arguments. Then write another program that calls CreateProcess() to launch the GUI program. But why would you want to do that because it is a huge waste of computer resources and time ????
What is ... the most important thing you pursue?
Getting my afternoon nap :)
Good day boys & girls...
Some (many) people use that greeting not to be offensive but to be humerous -- like the military drill sergeant who calls raw male recruits ladies. And people under the age of 21 years old are still technically children, or "boys and girls" -- which applies to at least half DaniWeb members.
line 15: void Createfile()
You forgot the class scope operator, so the compiler is treating it as a simple function that is not associated with any class.
Correct: void MyEmail::Createfile()
>>without the test file it compiles fine
Certainly -- because there is nothing that actually uses the MyEmail class.
If you have the source code then there be no *.lib, so don't worry about it. Please post all the code for your project, that is, all the *.cpp files and *.h files you created. And the Solution Explorer should show all those files.
You have the .h file but you failed to add the c++ code for that email class. If its some library you are using then you have to add the *.lib to the project.
We live in a capatilistic (sort of anyway) society. CEOs should get whatever companies are willing to pay them, even if its millions of $$$ and lots of benefits.
>>The goto statement I put in there, I have yet to test. I
Don't bother to test it. Just delete it. I know some teachers that will give students an F for turning in a program that contains one or more goto statements. The goto statement is almost never needed.
What you need are a couple loops, something like this pseudo code.
do while name is not "done"
prompt for name
get user input
// now enter all the grades
do while grade is greater than or equal to 0
prmpt for grade
get user input
calculate average grade
end while statement
end while statement
Thanks for replying AncientDragon. Well, I just solved my trouble. It was a very small niggle that was the troublemaker here. I developed the initial code as a project in vs.net 2005. After I spent the entire morning with it, I rebuilt the entire project this time in vs.net 2003 and it worked without a hitch. After this I realized the trouble. vs.net 2005 has a default charset of Unicode, while vs.net 2003 has a default charset of multibyteset. Changing the charset in vs.net 2005 to multibyteset or noset kills the issue.
I don't like that default UNICODE mode either because I always turn it off.
I have one more question. I am not sure if this I should ask this in a new thread. It is related to my current project anyways. This is the question. My first project here above is DLLProctTest. When I created this project I selected the option to create a dll and not a executable binary. Now my question is why does it build a DLLProctTest.lib along with DLLProctTest.dll when I build the project. Isn't a DLLProctTest.dll sufficient for any other application that wants to make use of the exported libraries? If I had to use this dll from any other application I also had to provide the link to this .lib file along with .dll file.
Many programs statically link to the dll and the *.lib is required to do that. You do …
what are a few of the error messages you got ? What compiler are you using ? My guess is that you did not write the code you posted because its too advanced for someone that asked the question you asked.
The code appears to have been written with Turbo C compiler ( clrscr() is only supported by Turbo C) so you will have to rewrite parts of that code that contains Borland-specific functions.
Ancient Dragon -
Thank you for your time.
Hope it helped :)
I think that is a file created by Microsoft Access. There are several ways to read it, and all of them require knowledge of SQL query language embedded in c or c++ program. Probably the most common way to read the file is via ODBC which is a set of functions that process SQL statements. There are a number of c++ ODBC classes available, some are free but most are not. And there are even some ODBC tutorials.
line 8 fails because cin requires a POD (Plain Old Data) type, unless you specifically write an operator >> overload method for the class. If you want to get the partnumber then do it something like this:
Invoice inv;
string partnumber;
string description;
cout << "Enter part number\n";
cin >> partnumber;
inv.setPartnumber(partnumber);
cout << "Enter description\n";
cin >> description;
inv.setDescription(description);
// Do the same for all the other class fields.
Remove the DllProctTest.lib from the DLLProctTest1 project -- load library is probably failing because it has already been statically linked to the *.exe program (just guessing). Also, the dll must be in one of the directories in the PATH statement or the current program's working directory. You might have to move the dll somewhere else.
You call functions that are loaded like you do in line 18 of the code you posted. Here is an example program that shows what to do. Note that it uses function pointers to call the functions.
What's your point? Vista hasn't <snip> up for you, therefore it wont <snip>for anyone else? LOL
Yes, <snip>hole.
Susy: Please repost your question about dbx files in the Tech Talk --> Microsoft Windows board because you will get more expert help there.
Hi please help me, I want to read an xml file with c++. Means, using COM+ logics how I can send my xml file in the local directory to my c++ code to read it? It would be really thankful if you could give me some ideas about that.
Read the links I posted. COM++ is very difficult and not for beginners, even people with advanced c++ knowledge have difficulties with it. So the boost libraries are probably what you would want, but you will have to do at least some of the research youself. I don't have neigher the time nor the inclination to do your work for you. Download boost, if you have not already done so, the read the documentation is is provided.
Has anyone seen the article on the front page of one of America's smut magazines that says Bill and Hillary will get a divorce if Hillary looses the election? I thought that was pretty funny, but probably not true.
You need to start reading the descriptions for the System::String methods in msdn so that you can learn how to look up the method(s) you need to solve your problems. What you need is a method that will locate (or find) the last '\\' in the string then another method that will take the substring of all the rest of the characters.
AdditionallyBy the way, I'm using Vista (IE7).
So do I and I have never seen (or at least noticed) that problem.
Yes I agree Dani has done a great job with DaniWeb. It didn't happen overnight or without a great deal of effort and planning.
use the Advance button, scroll down the page, and click the checkbox that says something about disabling smilies within the text.
Stormy Norman
It doesn't take a hero to order men into battle. It takes a hero to be one of those men who goes into battle.
He <Saddam Hussein> is neither a strategist nor is he schooled in the operational arts, nor is he a tactician, nor is he a general. Other than that he's a great military man.
The iterators I've worked with are defined like LinkedList<T>::iterator iter
and use begin() and end() to iterate through the list.
. A few weeks back I saw that a Mod gave a new member Reputation for using code tags. That's just to indicate how special it is that a new member actually reads all the info he/she is given.
Niek
I will do that for new members that take the time to read and understand the rules and how to post code. It is somewhat rare that a new member will do that.
I agree that if the rep rules were further explained in that intoductory message most newcomers wouldn't bother to read it.
tabs are considered white space so they are treated just like spaces. But you (jamthwee) are correct about newlines, so my previous suggestion will not work. But there is hope. Use getline() to read the entire line then stringstream to split it up into individual words similar to what I posted before. I was about to post the solution, but then I would be doing the OPs homework for him wouldn't I ?
If you want to put all those 100 numbers on one line you will have to change the font size to something very very tiny -- so tiny you probably won't be able to read the numbers.
before finishing the loop you have to reinitialize all variables back to their original values so that doesn't happen.