Two Questions, cout buffer problem, inline functions

Started by
5 comments, last by chbfiv 20 years, 6 months ago
-My first problem, I''m working at learning everything I can about C++ and so far I see alot of helpful time savers. My progress on a few projects has increased due to std::string and std::vector use. I also converted my File class to C++ only, and here in lies a odd problem. During a Loop to read in Lines of a file, cout and printf have this new effect.

char buffer[500] = {0};
string String1 = "A Line of Text for a Test...";
string String2 = "TEST";

//Loop until MyInFileStream.end()
     MyInFileStream.getline(buffer,500,''\n'');
     cout << String1 << String2 << endl;
     printf("%s %s\n",String1.c_str(),String2.c_str());
// End Loop
 
In console you see this, TESTne of Text for a Test... TESTne of Text for a Test... TESTne of Text for a Test... TESTne of Text for a Test... of course until the eof The Buffer is Putting String2 on top of String1. It has the same result if I flush() between them as well. The only way to get the correct effect is to seperate each section of text. Like so cout << "Some text" << endl; cout << String1 << endl; cout << " " << end; ... and so on. I dont quite understand why, this is my first problem with this. 2-Inline functions. How big is too big for inline functions? My draw member function for my Model class not only draws the triangle, but checks for color, or textures and such and adds them as needed. It makes for a rather large draw function, should it be inlined? Though not on my question list, Can someone explain why for(int i=0;i < somenum;++i) is faster then for(int i=0;i < somenum;i++) or are both these too slow and I should use something else?
-BourkeIV
Advertisement
someone needs to look up the details, but the issue is this, the C++ and C style IO systems are NOT linked together by default on most platforms, there is some form of function call you must make to set them as being synced together, so they do not step on each others toes in an asyncronous manner.

I''ll try to get back later with the answer, but if someone else finds it first, please post.
Just in case the obvious solution is not so obvious... Don''t use printf?
I was just showing you that it happens with both printf, and cout. You can take one of them out with the same result.
-BourkeIV
Take out printf and try it again.
The program im working on has no printf or even C includes. This is how I first came to the problem, I Added printf and stdio.h to see if it would happen with both cout and printf, and the same result. I then unincluded iostream and took out cout and it had the same result=/ I don''t know how you could misunderstand my last post.
-BourkeIV
Either there is something you aren''t telling us, or you have an incredibly broken compiler.

This topic is closed to new replies.

Advertisement