565 Posted Topics
Re: Easy input/output functions: #include <fstream> #include <sstream> #include <iostream> using namespace std; void open(string filename){ ifstream f_in (filename.c_str(), ios::in); if (!f_in){ cerr<<"Invalid file.\n"; return; } else{ string line; while(getline(f_in, line)){ cout<<line; } } } void save(string filename, string element){ ofstream f_out(filename.c_str(), ios::out); f_out<<element<<'\n'; } Now, you can put in some … | |
Re: **wikkido5000** Satrt your own thread in which you exaplin your situation. Don't hijack 2 years old threads. You can't mulriply a string '.' with a an integer dottimes, and why would you need that. If you really want that overloading of the console: import time import sys for i in … | |
Re: KY_Fan no one will do the actual homework/lab asignment for you, but, we can help you. As pyTony said, let's see what you did by now related to this lab asignment. Use what Gribouillis said regardless the equations of a circle which intersects a line. Also, for the graphical part, … | |
Re: You mean like this?: >>> l ['hi', 'there', 600] >>> newstring='' >>> for i in l: newstring+=str(i) >>> newstring 'hithere600' >>> | |
Re: The priority queue as an ADT is a container in which elements are stored acordingly to their priority. Have a look at how is implemented in C++: [Click me.](http://www.cplusplus.com/reference/stl/priority_queue/) As for **firdousahmad** you can't access a rear element in the Priority Queue (talking about the C++ implementation). The basic functions … | |
Hi. So I get this weird error message out from a QT application that i'm creating: 0xc0000005: read access violation at: 0x0, flags=0x0 Basically what I'm trying to do is to set in a QT List Widget an item of type QList Widget Item in which I store two things: … | |
Re: As firdousahmad said, you have to declare it in your calling function as void function(int *a). Let's see an example: #include <iostream> using namespace std; void ssum(int* ar){ for (int i=0;i<5;i++){ ar[i]=ar[i]+100; } } int main(){ int array[5]={2,5,6,7,8}; ssum(array); for (int i=0;i<5;i++){ cout<<array[i]<<" "; } return (0); } Another way … | |
Re: > return data, subs 1st mistake: you return a list, but as a return value in which you store that list, you put a variable f. Initialize f as a list, like `f=[]` than put the e, f=subcons(input) import re l = [] def subcons(data): match = re.search(r'(<[a-z]{3})', data) if … | |
Re: Here's the extend part from the Python Documentation: [Extend.](http://docs.python.org/tutorial/datastructures.html#more-on-lists) As for print ('a' 'b' 'c') it's the same with print ('a' 'b' 'c') as for the c='c' print ('a' 'b' c) think of it as c='c' print ('a' 'b' c) where c is a variable, and not a given character. … | |
Re: Well, you can get the CPU Serial Number or the HDD Serial Number. Either way, do a search on google with PC unique identifier as the keyword. | |
Re: [Here](http://www.codeguru.com/cpp/cpp/algorithms/article.php/c5123/Permutations-in-C.htm), this should help you. | |
Re: And also, have a look at [String functions](http://docs.python.org/library/string.html#string-functions) especially at the split one. | |
Re: [Here](http://www.cplusplus.com/doc/tutorial/classes2/), this should help you. Look at the definition of the constructor. | |
Re: If you type in `"gi"` it will go to gi, if you type `"q"` will exit the program, and if you type something else will go to the display and the eval functions. int main(){ string ans; for(;;){ cout<<"> "; cin>>ans; if (ans=="gi") gi(); else if (ans=="q") return(0); else{ display(); … | |
Re: On what platform are you programming? Try changing it to another, and use that. Try to run the .exe from the console and see what happens... | |
Re: you should put in a buffer like 1000 lines, copy that into the new file, and clear the buffer, and do it again. You see, after some time, it will fill up the buffer. you can put a condition using of course c++ libraries: while (getline(f_in, line)){ //do stuff if … | |
Inspired by some C and C++ threads regarding finding a specific pattern in a file. | |
Re: Duplicate thread: http://www.daniweb.com/software-development/c/threads/426230/calcultor | |
Re: is better to put as your ofstrema flag the `ios::out` and you could do it simply: #include <iostream> #include <string> #include <sstream> #include <fstream> using namespace std; int main(){ ofstream out("text12.txt", ios::out); cout<<"Insert string: "; string a; cin>>a; out<<a; return (0); } | |
Re: this should work for large amount of data: long double pow(long double nr, long double exp){ long double temp=1; for (;exp--;) temp*=nr; return (temp); } for like 23^53=1.48448e+072. | |
Re: here, this should fix it: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ char * list[4] = {"tom", "john", "albert", "lily"}; char answer[10]; printf("enter your name"); scanf("%9s", answer); int i, check=0; for(i = 0; i <4 ; i++){ if(strcmp(answer, list[i])==0){ printf("Found.\n"); check++; break; } } if (!check) printf("Not found.\n"); return … | |
Re: This is a program I did for another topic from the C department, maybe this will help you. Note that it's done in C, but the ideea matters. #include <stdio.h> #include <string.h> #include <stdlib.h> int line_num(char *filename){ FILE *f; char c; int lines = 0; f = fopen(filename, "r"); if(f … | |
Re: Here's your code a little bit revise, and with some new implementations. 1st of all, change Borland, because it's old. Ok, so here's the code: #include <iostream> using namespace std; #define MAX 100 struct arr{ int size; int ar[MAX]; }; void popArr(arr &ar); void printArr(arr ar); int main(){ arr arr; … | |
Re: Just replace the condition from line 5 with this one: `if ( argc < 2 )` and it should work fine. Tested on Linux: Ubuntu, and on win 7. On further posts, please post the question as well, because we can't guess that... | |
Re: See, I don't understand this > and the second column is the number of values behind it. but I see you have more than two columns. here's a suggestion: open file for read string c while(getline(fin, c)) read having ' '(space) as delimitter till '\n' @ process every element: 1st … | |
Re: If you just want to learn C, you can do it on linux via geedit, joe, or other text editors (vi, vim etc.) Windows: I prefer Eclipse with MinGW (you can have it packed and ready to go by the version for C/C++ developers as you can find [here](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers-includes-incubating-components/indigosr2) . … | |
Re: Here's a way of how you can do it: def read(): l = ["a.txt", "b.txt", "c.txt", "d.txt"] outfile = open("e.txt", "a") for i in l: infile = open(i, "r") outfile.write(infile.read().replace('.2', '[Replace sequence]')) or using pyTony's code: def read(): l = ["a.txt", "b.txt", "c.txt", "d.txt"] for i in l: with open(i, … | |
Re: Have you even bother to search on google?: [Link 1](http://msdn.microsoft.com/en-us/library/yeby3zcb(v=vs.80).aspx) [Link 2](http://www.gnu.org/software/libc/manual/html_node/Opening-Streams.html) [Link 3](http://www.cplusplus.com/reference/clibrary/cstdio/fopen/) | |
Re: Here's a quick example of the sorting part, done with gnome sort (stupid sort). #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 5 void GnomeSort(char* p[SIZE]){ int i=0; char* j; while(i<SIZE){ if (i==0||strcmp(p[i-1],p[i])==-1||strcmp(p[i-1], p[i])==0) i++; else{ j=p[i]; p[i]=p[i-1]; p[--i]=j; } } for (i=0;i<SIZE;i++) printf("%s\n", p[i]); } int main(){ char* p[SIZE]={"Bob", … | |
Re: noob26891 it would be better to start your own thread with your problem, than to revive a one year old thread. Also, please use correct indentation. As a side note, why do you use `int main( int argc, char *argv[])` in your main program, but still you don't use the … | |
Re: Poloblue, I thought you knew by now that if you have a question, you must open your own theread, and not to hijack threads that are older than 3 months. Please, open your thread in order to receive answers to your question. And by your erros I do get that … | |
Re: > I need help completing this by tomorrow afternoon!!! > Can anybody write this for me???????? I can tell you not to wait for someone to make your homework/project, because it won't happen. By solving this for you, you gain nothing, and you learn nothing. If you do have something … | |
Re: you could also do it like this def nr(*nrs): nr = "" for i in range (0, len(nrs)): a = str(nrs[i]) nr = nr + a return int(nr) print nr(1, 2, 3, 4, 5, 6) + 100000000 since Python works with strings alot. and if you want to put a … | |
Re: Indeed, what rubberman said. Post your very own attempt of doing this homework, and then, if you are stuck, we will try to help you. > How to find outputs the models with the least price per square meter. You need to do this: > Write a program that accepts … | |
Re: Have you checked this site? http://www.cplusplus.com/forum/unices/9187/ I'm not sure if this would work. #include <fstream> #include <iostream> #include <iterator> #include <string> #include <vector> using namespace std; int main(){ string filename; cout<<"File name: "; cin>>filename; ifstream input( filename.c_str(), ios::binary ); vector<char> buffer((istreambuf_iterator<char>(input)),(istreambuf_iterator<char>())); for (int i=0;i<(int)buffer.size();i++){ if (buffer[i]=='\n') continue; else cout<<buffer[i]; } … | |
Re: This is the complete time, but I don't know if it's what you actually want: #include <ctime> #include <stdio.h> #include <iostream> using namespace std; int main(){ time_t current=time(0); cout<<"Current time is: "<<ctime(¤t)<<endl; getchar(); return (0); } | |
Re: Have a look at this code snippet: http://www.daniweb.com/software-development/cpp/code/425892/prime-numbers-in-range But I wouldn't advise you to take it for grant, because it's a slow and unproducive algorithm. And, beside that, i put it there just as an example to your problem. Try to figure out a better algorithm, because mine is just … | |
Simple conversion between string and int. | |
Re: or you can just use stringstream, which is basically i/o-stringstream. #include <iostream> #include <sstream> #include <string> using namespace std; int main(){ string a="a"; int one=1; stringstream concat; concat<<a<<one; //a=concat.str(); //defines the string concat. cout<<concat.str()<<endl; return (0); } | |
Re: > bool checker(string 11, string 12, string 13, string 21, string 22, string 23, string 31, string 32, string 33); Your problem is rather simple to fix. I don't know exaclty what are those string 11, more speciffic the 11 part means, but, if you want to define a variable … | |
Re: That warning appears whenever you are trying to move/delete which has inside of it a prgram that is opened. For example, if you have a music folder, and you want to move it on another partition, but the files are opened in winamp or windows media player, and they are … | |
Re: > what is your question? As if you read my mind. Beside posting this long code, what seems to be the problem? I see you use these: #include<iostream.h> #include<conio.h> There are some topics related to that of using conio.h. And in C++ nowdays it's <iostream> not <iostream.h> | |
Re: Well, 1st of all, you should check the problem info/statement and analyse it a bit. You have to have in the end a 2x2 array, meaning with everything that is in the file, like a maxtrix. I don't know on what os are you trying to code. If you do … | |
Re: > I want to create a way to define interfaces without having to also write the class declaration that implements it. Are you reffering to those classes from OOP implemented virtual? > For anyone who doesn't know __interface makes all the functions within it automatically public and pure virtual. Indeed, … | |
Re: Here p is a char pointer, like char *. Take for example this: #include <stdio.h> char* f(char *p){ printf("%s\n", p); return (p); } int main(){ char *p={"Huga Huga"}; char *l; l=f(p); printf("%s", l); return (0); } Here I have passed the char *p to the function f. As you can … | |
Re: Well, either your graphich package is missing some stuff, or you have some prblems with your IDE. And btw, there is a topic on daniweb about this: http://www.daniweb.com/software-development/cpp/threads/180869/include-stdafx.h Here, this might also help: http://forums.codeguru.com/archive/index.php/t-152926.html | |
Re: Sorry pyTony, you forgot the extra ',' on your link, and of that it's not working: Thus, ido098 you should see here: http://wiki.videolan.org/Python_bindings | |
Re: Try to use like this: #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> using namespace std; instead of typing std::string. And it's better to include those things only in the Account.h header, like put it there: #include <iostream> #include <fstream> #include <vector> #include <string> #include <stdlib.h> #include <cctype.h> //etc. using namespace std; … | |
Re: I have stuble upon that error myself, and in some cases, it was due to some pointer arithmetic which turned out to point to the 0x0 address. Either you did something, and changed the address of some variable to the 0, meaning the null one, or it's something else. But … |
The End.