c++

Why can't I input the integers from a file?

I'm trying to get this C++ code to input a series of numbers from a text file: int x = 0; cin >> x; ifstream iffer; int numbers[12]; iffer.open("input.txt"); for (int i = 0; i < 12; i++){ iffer >> numbers[i]; } This doesn't seem to work on the Mac. Every cell will equal to 0 regardless of the value...

iPhone - OpenGL using C++ tutorial/snippet

Is there any good tutorial or code snippet out there on how to use OpenGL via C/C++ on the iPhone? ...

How to get unsigned equivalent of an integral type in C++?

Is there a way to get an unsigned equivalent (same size) of a signed integral type in C++? I'm thinking along the lines of: template<typename T> struct get_unsigned { }; template<> struct get_unsigned<int> { typedef unsigned int type; }; ... template<typename T> void myfunc(T val) { get_unsigned<T>::type u = std::abs(val); ...

Why do I need to include both the iostream and fstream headers to open a file

#include <iostream> #include <fstream> using namespace std; int main () { ofstream myfile; myfile.open ("test.txt"); return 0; } fstream is derived from iostream, why should we include both in the code above? I removed fstream, however, there is an error with ofstream. My question is ofstream is derived from ostream, why fstrea...

Access Violation When Accessing an STL Object Through A Pointer or Reference In A Different DLL or EXE

I experience the following problem while using legacy VC6. I just cann't switch to modern compiler, as I am working on a legacy code base. http://support.microsoft.com/kb/172396 Since there are no way to export map, my planned workaround is using static linking instead of dynamic linking. I was wondering whether you all had encountere...

Primitive constructors vs casting for conversion

What is the difference between: long myLong; float myFloat = (float) myLong; and: float myFloat = float(myLong); ...

cin erratic behaviour

i'm newby to C++. Small code as follows: int main(int argc, char* argv[]) { cout << "function main() .." << '\n'; char ch1; int int1; cin >> ch1; cin >> int1; cout << ch1 << '\n'; cout << int1 << '\n'; return 0; } when i run the program and input the following: function main() .. az i get : a 32767 i understand the 'a...

C++ cin questions

This seems to be weird: int main(int argc, char* argv[]) { cout << "function main() .." << '\n'; char ch = 0; double number_value=1.1; cin >> ch; cin.putback(ch); cin >> number_value; cout << "1 .. " << " " << cin.good() << " " << number_value << '\n'; cin >> number_value; cout...

Does it ever make sense to make a fundamental (non-pointer) parameter const?

I recently had an exchange with another C++ developer about the following use of const: void Foo(const int bar); He felt that using const in this way was good practice. I argued that it does nothing for the caller of the function (since a copy of the argument was going to be passed, there is no additional guarantee of safety with reg...

Problem with memset after an instance of a user defined class is created and a file is opened

I'm having a weird problem with memset, that was something to do with a class I'm creating before it and a file I'm opening in the constructor. The class I'm working with normally reads in an array and transforms it into another array, but that's not important. The class I'm working with is: #include <vector> #include <algorithm> using ...

Turn off the warnings due to boost library

Hello All, I am building an application in C++, Mac OS X, Qt and using boost libraries. Every time i build a project I get a huge list of warnings only from boost libraries itself. I want to turn off them so that I can see only my project specific warnings and errors. Can anybody help me? Thanks, Rahul ...

std::iostream link error vs2010 rc1

I'm converting a project from vs2008 to vs2010 and getting linker errors for std:ifstream/ofstream error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::is_open(void)const " (__imp_?is_open@?$basic_ofstream@DU?$char_traits@D@std@@@std@@QBE_NXZ) ...

Splash screen in Windows

How can I display a splash screen using C or C++ in Windows? What libraries or Windows components would be applicable? ...

Network file transfer in Windows

I want to transfer files across the network using C or C++. What topics should I look up? How can I do this? ...

Auto-Update for a Windows application.

Is there an open source project that allows for an auto-update of windows binaries? The Luau update library is very similar to what I'm looking for but it was abandoned in 2005. ...

Doesn't the Visual Studio 2008 compiler autocast to double with sqrt in C++?

Shouldn't the compiler automatically cast to a double in the following? At least according to Walter Savitch. #include <iostream> #include <cmath> using namespace std; int main(){ int k; for(k = 1; k <= 10; k++) cout << "The square root of k is: " << sqrt(k) << endl; return 0; }//error C2668: 'sqrt' : ambiguous call...

OutputDebugString + DebugView = not tabs!

I am dumping \t delimited data using using OutputDebugString and then use ex-Sysinternals DebugView to capture it. The problem is that all the data in DebugView appear to be space delimited, hence I need to perfrorm CTRL+H "\x20" "t" to replace spaces with the tabs before I can use it (I really need tab delimited data). Is there anywa...

Run process in .NET and C++

I search for the function that run programm by path, and working of main programm is stopped until run second programm. Can i do that by using System.Diagnostics.Process class? ...

Is it a good design to return value by parameter?

bool is_something_ok(int param,SomeStruct* p) { bool is_ok = false; // check if is_ok if(is_ok) // set p to some valid value else // set p to NULL return is_ok; } this function return true and set p to a valid value if "something is ok" otherwise return false and set p to NULL Is that a good or bad ...

Visual C++ 9 compiler options to make the program run faster

I have built an open-source application from the source code. Unfortunately, the original executable runs significantly faster. I tried to enable few compiler optimizations, but the result wasn't satisfactory enough. What else do I need to make in Visual Studio 2008 to increase the executable performance? Thanks! ...