- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 2
- Posts with Upvotes
- 2
- Upvoting Members
- 2
- Downvotes Received
- 2
- Posts with Downvotes
- 2
- Downvoting Members
- 2
87 Posted Topics
Re: [code=cpp] #include <iostream> #include <vector> using namespace std; int main(int argc, char **argv) { vector<double> num; vector<double>::iterator it; for (int i = 0; i < 10; ++i) { double tmp; cin >> tmp; num.push_back(tmp); } it = unique(num.begin(), num.end()); num.resize(it - num.begin()); for (size_t i = 0; i < num.size(); … | |
Re: so... is this work for you? [code=cpp] #include <iostream> #include <fstream> using namespace std; struct color { unsigned char blue; unsigned char green; unsigned char red; }; struct image { char header[54]; color data[480][640]; }; void threshold(image& Frame); int main(int argc, char **argv) { ifstream input_image; input_image.open("C:/Frame.bmp"); if (!input_image.is_open()) { … | |
Re: so if you have address of int - you can try this :) [code=cpp] int * money = (int*)0x7ffd8000; *money = 666; [/code] | |
Re: [CODE=CPP] #include <iostream> #include <cstring> using namespace std; int main() { char str[] = "0x0002,A5651QPR87GBZ094RTF52,D,A,000001,ABC ,10000.00 , EOT"; char* pch; pch = strtok(str, ", "); while (pch != NULL) { cout << pch << endl; pch = strtok(NULL, ", "); } return 0; } [/CODE] | |
Re: [code=cpp] #include <iostream> #include <sstream> #include <string> using namespace std; void print_int(int number){ stringstream tmp_stream; tmp_stream << number; string str_num(tmp_stream.str()); int sum = 0; for (size_t i = 0; i < str_num.size(); ++i){ cout << str_num[i] << ' '; sum+=str_num[i]-'0'; } cout << sum; } int main(int argc, char **argv) … ![]() | |
Re: all wrong :P here is simple fully dynamic/infinite(up to long long) array [CODE=CPP] #include <iostream> using namespace std; class array{ int* __date; unsigned long long __size; void resize(unsigned long long _size){ int* tmp = new int[_size]; copy(__date,__date+size(),tmp); delete[] __date; __date = tmp; __size = _size; } public: array(){ __date = … | |
Re: [QUOTE=tomtetlaw;916032]I am trying to initialize a vector inside a class's constructor, and I want the vector to be of type 'this' [code]std::vector<this>[/code] didnt work, [code] void* type = this; std::vector<type> [/code] that didn't work either, is there any other way to do it?[/QUOTE] try [code] void* type = (void*)this; std::vector<void*> … ![]() | |
Re: [QUOTE=hansel13;822838]This subroutine is very basic, however I am struggling. When the user types q (or Q) into the input when asked for the vendor name, the program should return false... However, this function is always returning true. MY if statement is clearly not working: (*vendorName != 'q' || *vendorName != … | |
Re: [url]http://www.cplusplus.com/reference/algorithm/min_element.html[/url] | |
Re: change [code=cpp]printf("%d",d); [/code] to [code=cpp]printf("%s", d.c_str()); [/code] | |
Re: or may be your code look like this [code=cpp] void foo() { char* tmp = new char[1024]; foo(); } [/code] | |
Re: remove this line [code=cpp] _cptPoints = new CPt [++_iSize]; [/code] | |
Re: [code=cpp] #include <iostream> int stripspaces(char str[]); using namespace std; int main() { char ar[100]; cout << "Enter a sentence and I will strip out the spaces:" << endl; cin.getline(ar, 99); cout << "Your sentence has " << stripspaces(ar) << " spaces" << endl; return 0; } int stripspaces(char str[]) { … | |
Re: [code=cpp] #include <iostream> using namespace std; int min(int x, int y) { return x < y ? x : y; } int max(int x, int y) { return x > y ? x : y; } int sumTo(int, int); int main() { int numb1, numb2; cout << "Please enter two … | |
Re: [code] #include <iostream> #include <fstream> using namespace std; int main() { string op; int val1; int val2; string val3; string val4; [COLOR="Red"]int ElementAmount = 0;[/COLOR] ifstream sourcefile; sourcefile.open("program.code"); [COLOR="Red"] if (!sourcefile.is_open()) { cout << "can't open program.code" << endl; return 1; }[/COLOR] while (sourcefile >> op >> val3 >> val4) … | |
Re: [code=c] int x; sscanf(str,"%*c%*d%*c%d", &x); [/code] | |
Re: [code=cpp] void lol(hash_map<string, wordStruct>& hashofwords){ ... } int main(){ ... lol(hashofwords); ... return 0; } [/code] | |
Re: line: 328 - you need operator[] line: 338 - you must return istream& line: 371 - you don't need "friend" key word line: 365 - &artist[0]??? what is this... you have 2 options: 1. make copy constructor for string class. 2. make function that return char* _string and use your … | |
Re: or make one class game_state and then output.write(&game_state, sizeof(game_state)) and to restore input.read(&game_state, sizeof(game_state)) | |
Re: one problem: [code] int* x = new int; //ok delete x; //ok [/code] but [code] int* x = new int; int* y = x; delete x; .... do something with y is wrong, because y is pointer to deleted object :} [/code] | |
Re: [code] element_t* buffer_end = &buf[length[COLOR="Red"]-1[/COLOR]]; [/code] btw. this is not working on VS2008 // &*container.begin() gets us a pointer to the first element but it work on gcc :P | |
Re: you can reverse using std::reverse :} std::reverse(string.begin(), string.end()); | |
Re: you can't use read() because: in text file "1 Bob 100" = string so 1 = char, but your class need int and ' ' = char too, but your class dont need it [code=cpp] #include <iostream> using std::cout; using std::cin; using std::endl; using std::ios; using std::ostream; #include <fstream> using … | |
Re: [code=cpp] #include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; int main() { ifstream ifs1("data1.txt"); vector<string> data1; if (ifs1.is_open()){ string line; while(getline(ifs1, line)){ data1.push_back(line); } } else{ cout << "Unable to open file data1.txt"; return 1; } ifstream ifs2("data2.txt"); if (ifs2.is_open()){ string line; while(getline(ifs2, line)){ for(size_t i = … | |
Re: my fix so far... still unplayable, but i need some rest. [code=cpp] #include <cstdio> #include <ctime> #include <iostream> #include <windows.h> #include <fstream> #include <vector> using namespace std; void savegame(vector<vector<int> >& terain); void loadgame(vector<vector<int> >& terain); bool zmbexist(vector<vector<int> >& sqarep, int posx, int posy); int nrzombies(vector<vector<int> >&plain); void display(vector<vector<int> >& terain); … | |
Re: here is my code, i know it is not what you ask, but i have fun to wright it. [code=cpp] #include <iostream> #include <fstream> #include <string> using namespace std; void read_lines(fstream& file, int& line, string& last_lines){ string t; if (getline(file, t, '\n')){ read_lines(file, line, last_lines); } if (line >= 0){ … | |
Re: [code=cpp] string dir_name; getline(cin, dir_name); ifstream file(dir_name.c_str()); [/code] | |
Re: [code=cpp] int& sumz(int x,int y) { int *sum = new int; *sum = x + y; return *sum; } [/code] | |
Re: using std::string and operator overloading, yes it is able | |
| |
Re: here is the fix for save game, problem was in save game function.... [code=cpp] #include<iostream.h> #include<fstream> #include<string> using namespace std; char choice; int missionNumber = 0; int smissionNumber; int gamsoldiers = 25; int ricsoldiers = 25; int galsoldiers = 25; int salsoldiers = 25; int amesoldiers = 25; void mission1(); … | |
Re: hm.. why free dos? there is hm... what was name....... linux? | |
Re: can you use std::sort(A, A+1000) and if A[j] == A[j+1] cout << A[j] | |
Re: [code=cpp] #include <iostream> #include <stdio.h> #include <math.h> #include <stdlib.h> #include <windows.h> #define PI 3.14159265 using namespace std; int main() { //double param, result, exp; float b = 0, c = 0, d = 0/*, e= 0, f = 0*/; //float w =0, x=0, y=0; //int z=0; char a; //int t2, … | |
Re: in second you create std::vector<int>::const_iterator pos every time when you loop and then change value :) in first when loop it only change value | |
Re: [code=cpp] #include <iostream> #include <string> using namespace std; string encrypt(string data, const string& key); int main(int argc, char **argv) { const string key = "lolz"; string test = "I'm C++ string"; cout << "before encryption: "; cout << test << endl; test = encrypt(test, key); cout << "after encryption: "; … | |
Re: try [code=cpp] #include <vector> int main() { std::vector<const int> v(); return 0; } [/code] | |
Re: in math.h [code=cpp]string question1[80];[/code] - this is array of 80 strings, but you need only 1 string, not 80. so [code=cpp]string question1;[/code] is ok. but in class you can't define string question1 = "What is the net?"; this must be done in constructor, so you need only string question1; for … | |
Re: [main.cpp] [code=cpp] #include "wagon_construction.h" #include <iostream> int main(int argc, char **argv) { wagon_construction train; train.insert_head(GREEN); train.insert_head(GREEN); train.insert_head(RED); // train.insert_head(BLUE); // train.remove_all(GREEN); train.move_first_to(GREEN,BLUE); std::cout << train.get_num(GREEN) << std::endl; train.duplicate(); train.print(); return 0; } [/code] [wagon_construction.h] [code=cpp] #ifndef WAGON_CONSTRUCTION_H_ #define WAGON_CONSTRUCTION_H_ #include <list> using namespace std; enum wagon{ RED, BLUE, GREEN }; … | |
Re: [code=cpp] double findWaist(double weight, int age) { double waist; if (age > 28) (weight/ 5.7) + ((age - 28) / 2) * .01; else waist = (weight/ 5.7); return waist; }[/code] after if (age > 28) it must be waist = (weight/ 5.7) + ((age - 28) / 2) * … | |
Re: go to workspace directory -> project directory -> Debug and there will be executable file | |
Re: [code=cpp] std::cout << "text[0] = " << (int)text[0] << '\n'; [/code] | |
Re: try f.write(str.GetBuffer(str.GetLength()),10); | |
Re: [code=cpp] #include <iostream> using namespace std; double addRange(int x, int y); int main() { int x, y; cout << "Please enter the low value of the range to add: " << endl; cin >> x; cout << "Please enter the high value of the range to add: " << endl; … ![]() | |
Re: #define strcpy_s strcpy :D | |
Re: my old program - it only search for path, but not short [url]http://www.dev-spot.com/forums/index.php?topic=57.msg309#msg309[/url] | |
Re: you can use SDL_mixer [url]http://www.libsdl.org/projects/SDL_mixer/[/url] | |
Re: [code=cpp] for( int i = 0; i < 5; i++) //loop 1 { std::string str= "Number1 - Number2"; for( int i2 = 0; i2 < 100; i2++) //loop2 { std::string::size_type index = str.find("*", 0); if( std::string::npos != index ) { //Do some stuff if a "*" was found in str … |
The End.