c++

C++ remove trailing new line from text file

Is there a way in C++ to remove/trim a trailing new line from a text file? For example content content content content content content <- this line in the text file is empty and needs to go -> ...

Redeclaration of enumerator

I got an error: redeclaration of enumerator message when I compile my codes, please kindly see the code below from my foo.h header file, //foo.h struct FG { enum { black = 1, red = 2, green = 3 }; }; struct BG { enum { black = 1, red = 2, green = 3 }; }; My question is, why I...

Different char type in windows programming

Hi all Recently, I meet some tasks about the char/string on windows platform. I see that they are different char type like char, TCHAR, WCHAR, LPSTR, LPWSTR, LPCTSTR. Can someone give me some information about it? And how to use like the regular char and char *. I cam confused about these types? Best Regards, ...

Creating c++ object on the stack, trying hard not to ever allocate.

Suppose I have a class class A { public: A(int i); ~A(); private: B b; // Want <- this guy to be constructed with i in A's constructor! }; I want b to be constructed in the constructor with particular parameters that aren't known until A is constructed. If I were to do the following in A's constr...

Help reading every five lines from text file c++

As part of a larger assignment I have to create a method in a class that can read five lines of data then put that data into a dynamically created object. I am not sure how to go about getting the five lines of data separately into the object. The code should help to explain better but it does not work as desired. If someone can spot my ...

Dynamic allocation with scanf()

My question is exactly the same as this one. That is, I'm trying to use scanf() to receive a string of indeterminate length, and I want scanf() to dynamically allocate memory for it. However, in my situation, I am using VS2010. As far as I can see, MS's scanf() doesn't have an a or m modifier for when scanning for strings. Is there any ...

How to call C++ functions in my assembly code

I need to call PrintResult from my assembly to display the result. I know I have to use extrn _PrintResult somewhere, and I should call the function using call _PrintResult but I'm not sure quite sure how to use it. any suggestions public _Square .386 .model flat .code _Square proc mov eax, [esp+4] imul eax ret _Square endp .....

Interprocess communication: one server and multiple clients

I have one "server" process running, which will fetch data over the network for other processes running on the same machine as the server process. How should I transfer data from the local server process and the local clients? ...

Why is memcpy not functioning properly?

Hey everyone, I have a class for an RDT Header that holds information for an implementation of several reliable data transfer protocols. I need to attach that information (a total of 12 bytes) to my send buffer to transfer it over the socket. I am trying to use memcpy to do this but for some reason it just leaves junk inside the buffer....

Returning a pointer from a member fucntion in C++

Hello I have a class with a function that returns a pointer: int* Maze::GetStart() { int startNode = 1; return &startNode; } Will the value of startNode be erased after the function returns the pointer? If I did this instead would the value be saved? int Maze::GetStart() { int startNode = 1; return startNode ; } m...

C++ in G++ - Segmentation Fault when not using pointers

I'm trying to use G++ to compile some C++ code. It seems to work fine in other compilers, but for whatever reason, G++ won't produce working output. Disclosure: This is part of a homework assignment, but I feel like it's more of a compiler issue, since it works in other compilers. Here's the snippet that's wreaking havoc: set<int> t1,...

The book about writing search engine. Recommend some...

I want to learn more about the full-text search. Recommend please a few good books in which would be well described used algorithms and data structures, which must describe how to write simple search engine. I use C++. Thanks! ...

List iterator error

Hello, I make stack based in std:list. Now i try to make functions for showing all elements from this stack: I try to declare iterator: void show_elements() { list<T>::iterator it; } But i get error: error: dependent-name ‘std::list::iterator’ is parsed as a non-type, but instantiation yields a type What's wrong? Thank you. ...

Networking for Xna (C#) and C++?

Me and some friends were thinking about making an online game with XNA game studio. Our games mainly used Winsock for the networking portion, but our most recent project used RakNet where the server was in C++ and the Client used a small RakNet wrapper I wrote. As far as I know XNA can't really use DLLs, so I was wondering what a good ne...

Different cases for exception occuring in C, C++

Currently I need to fix exceptions occurring in the code. Could someone specify various points like in what cases or when do exceptions occur in C, C++ languages. and what is the best approach to handle exceptions in C, C++ languages. ...

Is there any way to speed up frequent file write operations? CFile.

My task is to write small parts of data to file frequently and guaranteed. It's a some type of logging system, that must provide a guaranteed safety and speed of saving data to disk. I found that brakes appear in the Flush() function that is called too often. So, I decided to get rid of it. I used flags, that prohibit buffering and cach...

How can completely port a qt3 library to qt4?

I have been stumbling through some different steps to do this. I ran the qt3to4.exe on the files with compile errors and got though a lot of conversion steps, however now I am getting this error: 1>c:\qt\4.7.0\src\qt3support\widgets\q3toolbar.h(64) : error C2039: 'ToolBarDock' : is not a member of 'Qt' and 55 other similar errors. This...

Get a process Owner Name in mfc

Hi All, I want to get the user name who has launched the given application. For Example if Outlook or IE is launched I need to get the Name of the user who has launched it. This should be generic across all Windows OS . But the solution given below is failing in Windows 2003 user ,in both ADMIN and Standard User. ...

Where should default parameters be specified?

At my workplace, usually default parameters are specified in the declaration.What is the normal custom? Should I specify default parameters in method declaration or method definition? EDIT: Is there any way to specify default parameters for references? EDIT: Can someone please provide an example of default arguments for reference para...

Is there any alternative to FFMPEG to create flv video programmatically?

I need to create flash movies and the FFMPEG hava GPL license problem , I need to create only flv file Is there any alternative ? ...