Search Results

Search found 1771 results on 71 pages for 'knowing me knowing you'.

Page 6/71 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • How to insert into std::map.

    - by Knowing me knowing you
    In code below: map<string,vector<int>> create(ifstream& in, const vector<string>& vec) { /*holds string and line numbers into which each string appears*/ typedef map<string,vector<int>> myMap; typedef vector<string>::const_iterator const_iter; myMap result; string tmp; unsigned int lineCounter = 0; while(std::getline(in,tmp)) { const_iter beg = vec.begin(); const_iter end = vec.end(); while (beg < end) { if ( tmp.find(*beg) != string::npos) { result[*beg].push_back(lineCounter);//THIS IS THE LINE I'M ASKING FOR } ++beg; } ++lineCounter; } return result; } How should I do it (check line commented in code) if I want to use insert method of map instead of using operator[]? Thank you.

    Read the article

  • C++: How do I pass a function(without knowing its parameters) to another function?

    - by Ninja
    Hi all. I'm trying to create a function that will store and repeat another function given as a parameter for a specific amount of time or repeats given. But when you want to pass a function as a parameter you have to know all of its parameters before hand. How would I do if I wanted to pass the function as one parameter, and the parameters as another? void AddTimer(float time, int repeats, void (*func), params); // I know params has no type and that (*func) is missing parameters but it is just to show you what I mean Thanks in advance

    Read the article

  • How to override virtual function in good style? [C++]

    - by Knowing me knowing you
    Hi, guys I know this question is very basic but I've met in few publications (websites, books) different style of override virtual function. What I mean is: if I have base class: class Base { public: virtual void f() = 0; }; in some publications I saw that to override this some authors would just say: void f(); and some would still repeat the virtual keyword before void. Which form of overwriting is in good style? Thank you for your answers.

    Read the article

  • Is correct name enough to make it happen?

    - by Knowing me knowing you
    Guys, I've just dipped in to limits.h by MS. I tried to check what's the return type for max() fnc and to my surprise I see something like this: // TEMPLATE CLASS numeric_limits template<class _Ty> class numeric_limits : public _Num_base { // numeric limits for arbitrary type _Ty (say little or nothing) public: static _Ty (__CRTDECL min)() _THROW0() { // return minimum value return (_Ty(0)); } static _Ty (__CRTDECL max)() _THROW0() { // return maximum value return (_Ty(0));//EXACTLY THE SAME WHAT IN min<<------------------ } //... other stuff }; so how is it possiple that in both min and max return does exactly the same? So does it mean if I would write makeSanwich() return (_Ty(0)) it would make a sandwich for me? How is it possible that having this same code just fnc names different we are getting different results?

    Read the article

  • Why do I have to give an identifier?

    - by Knowing me knowing you
    In code: try { System.out.print(fromClient.readLine()); } catch(IOException )//LINE 1 { System.err.println("Error while trying to read from Client"); } In code line marked as LINE 1 compiler forces me to give an identifier even though I'm not using it. Why this unnatural constrain? And then if I type an identifier I'm getting warning that identifier isn't used. It just doesn't make sense to me, forcing a programmer to do something unnecesarry and surplus. And after me someone will revise this code and will be wondering if I didn't use this variable on purpouse or I just forgot. So in order to avoid that I have to write additional comment explaining why I do not use variable which is unnecessary in my code. Thanks

    Read the article

  • Client/Server app

    - by Knowing me knowing you
    Guys could anyone tell me what's wrong am I doing here? Below are four files Client, main, Server, main. I'm getting an error on Client side after trying to fromServer.readLine(). Error: Error in Client Software caused connection abort: recv failed package client; import java.io.*; import java.net.*; import java.util.Scanner; public class Client { private PrintWriter toServer; private BufferedReader fromServer; private Socket socket; public Client( )throws IOException { socket = new Socket("127.0.0.1",3000); } public void openStreams() throws IOException { // // InputStream is = socket.getInputStream(); // OutputStream os = socket.getOutputStream(); // fromServer = new BufferedReader(new InputStreamReader(is)); // toServer = new PrintWriter(os, true); toServer = new PrintWriter(socket.getOutputStream(),true); fromServer = new BufferedReader(new InputStreamReader(socket.getInputStream())); } public void closeStreams() throws IOException { fromServer.close(); toServer.close(); socket.close(); } public void run()throws IOException { openStreams(); String msg = ""; Scanner scanner = new Scanner(System.in); toServer.println("Hello from Client."); // msg = scanner.nextLine(); while (msg != "exit") { System.out.println(">"); // msg = scanner.nextLine(); toServer.println("msg"); String tmp = fromServer.readLine(); System.out.println("Server said: " + tmp); } closeStreams(); } } package server; import java.net.*; import java.io.*; public class Server { private ServerSocket serverSocket; private Socket socket; private PrintWriter toClient; private BufferedReader fromClient; public void run() throws IOException { System.out.println("Server is waiting for connections..."); while (true) { openStreams(); processClient(); closeStreams(); } } public void openStreams() throws IOException { serverSocket = new ServerSocket(3000); socket = serverSocket.accept(); toClient = new PrintWriter(socket.getOutputStream(),true); fromClient = new BufferedReader(new InputStreamReader(socket.getInputStream())); } public void closeStreams() throws IOException { fromClient.close(); toClient.close(); socket.close(); serverSocket.close(); } public void processClient()throws IOException { System.out.println("Connection established."); String msg = fromClient.readLine(); toClient.println("Client said " + msg); } } package client; import java.io.IOException; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here try { Client client = new Client(); client.run(); } catch(IOException e) { System.err.println("Error in Client " + e.getMessage()); } } } package server; import java.io.IOException; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Server server = new Server(); try { server.run(); } catch(IOException e) { System.err.println("Error in Server " + e.getMessage()); } } }

    Read the article

  • Why do I have to pay for something that I'm not using?

    - by Knowing me knowing you
    Guys just finished reading one of my college books about threads in Java and I was informed that lock - what ever it is, is in Object class. So it looks like even though I'm not using threaded classes my objects will be heavier because of that? Don't you think that it's a bit annoying and unfair to expect from anyone to pay for something s/he have not intention of using? Thanks

    Read the article

  • Shall I optimize or let compiler to do that?

    - by Knowing me knowing you
    What is the preferred method of writing loops according to efficiency: Way a) /*here I'm hoping that compiler will optimize this code and won't be calling size every time it iterates through this loop*/ for (unsigned i = firstString.size(); i < anotherString.size(), ++i) { //do something } or maybe should I do it this way: Way b) unsigned first = firstString.size(); unsigned second = anotherString.size(); and now I can write: for (unsigned i = first; i < second, ++i) { //do something } the second way seems to me like worse option for two reasons: scope polluting and verbosity but it has the advantage of being sure that size() will be invoked once for each object. Looking forward to your answers.

    Read the article

  • Is it the most common case?

    - by Knowing me knowing you
    Why when I click on the x button to close the window in a Java application only the window dissapears and the applicaton is still running. I've read so many times that java designers tried to cater Java behaviour for the most common needs of programmers and save they precious time and so on and so on. What's more common case than closing app when I click on a X button?

    Read the article

  • What am I calling?

    - by Knowing me knowing you
    Is there a way to check inside a fnc what is this fnc name? I'm working currently on LargeInt class and I've realized that code for oparator and operator< is almost identical so I would like to know what operator is calling me and react accordingly. Thank you.

    Read the article

  • Do I have to start from beginning?

    - by Knowing me knowing you
    If I have: std::size_t bagCapacity_ = 10; std::size_t bagSize = 0; A** bag = new A*[bagCapacity_]; while (capacity--) { bag[capacity] = new A(bagSize++);//**here I'm loading this array from the end is it ok?** } And also can I delete those object from starting at the end of the array? while(capacity--) { delete bag[capacity]; } Question in a code.

    Read the article

  • In PHP how do a translate a date to numerical format not knowing the format of the string beforehand

    - by stormist
    Examples of the translations I need to do: $stringDate = "November 2009"; $output = "11/09"; $stringDate = "October 1 2010"; $output = "10/01/2010"; $stringDate = "January 2010"; $output = "01/10"; $stringDate = "January 9 2010"; $output = "01/09/2010"; Note that I do not know which format the $stringDate will be in and the lack of commas in the month day year set. Thanks for any help anyone might offer.

    Read the article

  • Should it be in a namespace?

    - by Knowing me knowing you
    Do I have to put code from .cpp in a namespace from corresponding .h or it's enough to just write using declaration? //file .h namespace a { /*interface*/ class my { }; } //file .cpp using a::my; // Can I just write in this file this declaration and // after that start to write implementation, or // should I write: namespace a //everything in a namespace now { //Implementation goes here } Thanks.

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >