#### Archived

This topic is now archived and is closed to further replies.

# Two Questions, cout buffer problem, inline functions

This topic is 5172 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

-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?

##### Share on other sites
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.

##### Share on other sites
Just in case the obvious solution is not so obvious... Don''t use printf?

##### Share on other sites
I was just showing you that it happens with both printf, and cout. You can take one of them out with the same result.

##### Share on other sites
Take out printf and try it again.

##### Share on other sites
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.

##### Share on other sites
Either there is something you aren''t telling us, or you have an incredibly broken compiler.

• ### Forum Statistics

• Total Topics
628710
• Total Posts
2984334

• 23
• 11
• 10
• 13
• 14