Hey, does anybody know how to check whether the file descriptor is valid?
Type: Posts; User: creativeinspira
Hey, does anybody know how to check whether the file descriptor is valid?
Hey Guys,
When writing a shell, what is the technique for supporting interactive programs such as pico, more, and less. Suppose that a program has both, a keyboard input as well as a piped one...
Simply moving it to a header file works. But if you put the function declaration in the .h file and definition in .cpp file that does not work.
Before I had a function in a .h file. Once I move it to a cpp file it works fine. I have done it like this:
template<typename T>
void func(vector<T>& vec)
{
}
int main()
st is the type of somestruct
Hey guys,
Here is what I am doing:
template <typename T>
void func(vector<T> vec)
{
..
..
Hey guys. Do any of you know a way to sort a vector of structs in STL? I tried using a comparator such as
class compare
{
bool operator(structtype st1, structtype st2)
{
...
Hey Folks. Question here. I am writing a program in C++ in linux. I need to time a piece of code. Currently I am using the times function in <sys/times.h>. It gets me the time alright (time...
Hi everybody. Does anybody know of a way to insert a line of text in the begging of the textfile without having to read an entire file in a loop? Preferably using ifstream? Thank you for the...
Thanks to you for all who tried to help. I can't post detailed code. I will just figure this out myself.
Nope.
Yet even stranger:
If I add the following code, the core dump goes away:
void somClass::addNewInt(const int& newInt)
{
vector<int> vec2;
vec2.push_back(newInt);
I realized something else too: if I cout the newInt, it is correct. However, if I try to push it, a core dump happens. Now, here is the kicker: if I replace newInt with some other integer (local ...
Hey everybody. I have an issue where pushing a new item onto an STL vector, I get a core dump. Now, the capacity of the vector is not exceeded (its only 3). The vector contains integers. Now, in...
Thank you. So I can just do #define NDEBUG in my main file, and then all the code between #ifndef and #endif will be deactivated?
Hi everybody. I was wondering if there is a way in C++ to have debug messages, and the ability to turn them off. For example, lets say I would like my program to have two modes. One mode is the...
This confirms it, thank you.
Hey everybody. I understand that erasing elements in the vector invalidates the iterators. If you consider the following code:
#include <iostream>
#include <vector>
using namespace std;
...
Yeah, thanks everybody I fixed it.
I think you are right. My file is 7 bytes somehow. I don't quite understand why, since hello is the only thing in it. I examined it in hex editor, and it appears to confirm it. I attached the...
The output is:
<--hello
Here is my code. I am using g++ on ubuntu linux btw.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
Hey Guys. This is a weird one. Basically what I am doing is reading a string from the file using getline(file, buffer) where buffer is a C++ string. For example: lets say the file contains the string...
Hi Everybody. If any of you know how to make an STL set of classes or structs, that would be cool. Which operators do you need to implements so if I have myclass, I can have an stl set of type...
This will get the usage only for the dynamic memory. However, I want the usage for the whole program. Thanks for trying to help though.