Hiya.
I'm trying to read a file line by line to a string type variable using the following code:
#include <iostream>
#include <fstream>
ifstream file(file_name);
if (!file) {
cout << "unable to open file";
exit(1);
}
string line;
while (!file.eof()) {
file.getline(line,256);
cout<<line;
}
file.close();
it won't co...
Hiya.
I'm using std::getline to read lines from a file,
how can I move forward a few lines? do I have to use getline the number of lines I want to skip?
thanks!
...
I have the following code to assign a value to all the elements of a vector:
x = 100;
for (int i=0;i<vect.size();i++)
{
vect[i] = x;
}
It's straightforward enough, but I'm wondering if there is a function in the STL that does the same thing; something like for_each, but for assignment.
...
Does anyone know how to open an image, specifically a jpg, to a byte array in C or C++? Any form of help is appreciated.
Thanks!
...
Hi guys!
I realize it's probably something strange, but here is what I have.
I have an application (handwriting recognition engine) written in C/C++. This application has Perl wrapper which was made by application's authors using SWIG. My website is written in PHP, so I'm looking for some ways to make PHP work with C/C++ application.
...
I know that the C++ standard says that return 0 is inserted at the end of main() if no return statement is given; however, I often see recently-written, standard-conforming C++ code that explicitly returns 0 at the end of main(). For what reasons would somebody want to explicitly return 0 if it's automatically done by the compiler?
...
Hi all,
I've got a c++ app, with the following main.cpp:
1: #include <stdio.h>
2: #include "HeatMap.h"
3: #include <iostream>
4:
5: int main (int argc, char * const argv[])
6: {
7: HeatMap heatMap();
8: printf("message");
9: return 0;
10: }
Everything compiles without errors, I'm using gdb (GNU gdb 6.3.50-20050815 (Appl...
Double has range more than a 64-bit integer, but its precision is less dues to its representation (since double is 64-bit as well, it can't fit more actual values). So, when representing larger integers, you start to lose precision in the integer part.
#include <boost/cstdint.hpp>
#include <limits>
template<typename T, typename TFloat>...
I'm doing some specific signal analysis, and I am in need of a method that would smooth out a given bell-shaped distribution curve. A running average approach isn't producing the results I desire. I want to keep the min/max, and general shape of my fitted curve intact, but resolve the inconsistencies in sampling.
In short: if given a se...
Hello, I try to call a function which passed as function pointer with no argument, but I can't make it work.
void *disconnectFunc;
void D::setDisconnectFunc(void (*func)){
disconnectFunc = func;
}
void D::disconnected(){
*disconnectFunc;
connected = false;
}
...
Hi,
I have a abstract base class A and a set of 10 derived classes. The infix operator is overloaded in all of the derived classes
class A{
public:
void printNode( std::ostream& os )
{
this->printNode_p();
}
protected:
virtual void printNode_p( std::ostream& os )
{
os << (*this);
}
};...
By referring to http://stackoverflow.com/questions/315948/c-catching-all-exceptions
try {
int i = 0;
int j = 0/i; /* Division by 0 */
int *k = 0;
std::cout << *k << std::endl; /* De-reference invalid memory location. */
}
catch (...) {
std::cout << "Opps!" << std::endl;
}
The above run-time error are unable to be...
Hey I am trying to write some numbers to a file, but when I open the file it is empty. Can you help me out here? Thanks.
/** main function **/
int main(){
/** variables **/
RandGen* random_generator = new RandGen;
int random_numbers;
string file_name;
/** ask user for quantity of random number to produce **/
...
Ok, so I have my basic linked Queue class with basic functions such as front(), empty() etc.. and I have transformed it into a template. Now, I also have a class called Student. Which holds 2 values: Student name and Student Id. I can print out a student with the following code..
Student me("My Name", 2);
cout << me << endl;
Here is ...
Hiya.
can anyone assist me in finding the proper formula for quad normalization ?
using c++ with opengl.
thank you!
...
Here's my code so far:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
int count = 0;
string fileName;
string keyWord;
string word;
cout << "Please make sure the document is in the same file as the program, thank you!"
<< endl << "Please input document name: " ;
...
Say I want a function that takes two floats (x and y), and I want to compare them using not their float representation but rather their bitwise representation as a 32-bit unsigned int. That is, a number like -495.5 has bit representation 0b11000011111001011100000000000000 or 0xC3E5C000 as a float, and I have an unsigned int with the same...
I have no idea what this means. But here is the code that it supposely is happening in.
//=======================================================================================
// d3dApp.cpp by Frank Luna (C) 2008 All Rights Reserved.
//=======================================================================================
#include "d...
I'm writing an application in C# that uses proxies. The proxies are sending the HTTP_X_FORWARDED_FOR during HTTP requests, and this is unwanted behavior.
I am extending the Interop.SHDocVw axWebBrowser (aka Internet Explorer) control right now, but can take another approach if needed for this problem.
Is there some way to suppress thi...
Hi,
I try to read file /proc/'pid'/status, using c program. The code is as follows, and even I use sudo to run it, the prompt still keeps throwing "Unable to open file". Please let me know if you have any ideas on how to fix this. thanks
Richard
...
int main (int argc, char* argv[]) {
string line;
char* fileLoc;
if(ar...