w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Performance difference of iostream console output between Windows and OSX?
std::endl flush the line. It is quite expensive to do this. Try to do : std::cout << i << ' '; In most other usual interactive I/O scenarios, std::endl is redundant when used with std::cout because any input from std::cin, output to std::cerr, or program termination forces a call to std::cout.flush(). Use of std::endl in place of ' ', encouraged by some sources, may significantly degrade output performance. Source EDIT : Output operation are costly and depend on external factors. This is why it is slow here. For example, the terminal application being used can be factor of some performance issues. You can avoid that by redirecting the output to /dev/null/ : ./a.out > /dev/null On output performance, you can read this : http://codeforces.com/blog/entry/52

Categories : C++

Program with embedded sql gives compilation error
First, the connection to database is missing, you should have something like : int i=0; EXEC SQL CONNECT TO target [AS connection-name] [USER user-name]; Or PGconn *conn; int buf_ptr=0; int i=0; conn = PQconnectdbParams(const char **keywords, const char **values, int expand_dbname); then save your source file as prog.pgc and run : ecpg prog.pgc this will create a file called prog.c which can be compiled as a standard C file.

Categories : SQL

C++ Error
You want just iostream #include <iostream> I suspect the book is very old. Names are qualified in the std namespace, so you may want to add using namespace std; For now at least.

Categories : C++

Java : Can't capture console output of a console program (Blockland.exe)
You are running a DOS console application, which does not necessarily write to stdout or stderr, but it writes to the "console". It's nearly impossible to capture the "console" output reliably. The only tool that I have ever seen that is able to capture console output is expect by Don Libes, and that does all sorts of hacks.

Categories : Java

Why does compiling with cause a 500 error on Apache?
You can run into this problem when the C++ compiler version on the local machine does not match the version on the server. In all likelihood, #include <iostream> triggers the compiler to bring in code from libc++, while leaving it out also leaves out the libc++ dependency. To avoid this problem, you can try static linking with -static. This has the advantage of pulling in all the relevant code from your local copy, but does result in a much larger executable and somewhat larger memory footprint. Alternately, you can investigate the required shared library versions using the tool ldd, and ensure appropriate versions get installed on the server machine.

Categories : C++

Console.WriteLine release mode compilation
Use something like NLog with conditional compilation so that it's not included in the Release build. Then you can just tail the log while you're debugging and get the same information without it being leaked to users. Or, if you're more comfortable using Console.WriteLine, just wrap calls to that with conditional compilation, like so: #if DEBUG Console.WriteLine("Debug version"); #endif

Categories : C#

High CPU usage when reading from console
I assume you have some kind of code that checks the status of readLine(), otherwise Java will continue to block. String line = null; while ((line = br.readLine()) != null) { // handle contents of line here } You may be better off using the Scanner class to read user input. Scanner sc = new Scanner(System.in); int num = sc.nextInt(); ....

Categories : Java

java: I cannot run the program after compilation? Help me
NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time. For example if we have a method call from a class or accessing any static member of a Class and that class is not available during run-time then JVM will throw NoClassDefFoundError. Obvious reason of NoClassDefFoundError is that a particular class is not available in Classpath, so we need to add that into Classpath or we need to check why it’s not available in Classpath if we are expecting it to be. There could be multiple reasons like: Class is not available in Java Classpath. You might be running your program using jar command and class was not defined in manifest file's ClassPath attribute. Any start-up script is overrid

Categories : Java

SQLite3 on freebsd - compilation of first program
You need to tell gcc where to look for includes, and you need to tell it to link against sqlite's library, which is probably called libsqlite.so You're looking for something along the lines of gcc -I /usr/local/include -lsqlite test.c.

Categories : C++

How to run a java program upon compilation of class
you can right click your project select properties / builders / new. this will add an external program to be run. after project compilation. (it will only be once per compile, not once per compilation unit, which is what i think you are referring to). however its easy enough to keep track of that by your external program, and run something for every updated compilation unit (or newly generated class file)

Categories : Java

Is there a way to analyze static maps usage beyond the basic console reports?
Just an idea: Add a serverside script as icon to the StaticMap-URL. The url of this script(icon) should contain a random parameter to prevent google from caching this script(icon), and additionally parameters that are populated with the desired details(url of the current page, IP, UserAgent) The response of the script should be an image that is suitable to be used as a icon for a static map(may be a 1x1 transparent png) The script may store the supplied parameters in a DB, you should be able to create detailed statistics of the StaticMaps-loads.

Categories : Google Maps

C Program Compilation issue involving Glib2 library?
It sounds as if what you did in order to compile the libraries in non-default (i.e. non-system) locations was maybe wrong. For packages using autoconf (i.e. that have a configure script in the source root) you're supposed to use the --prefix option to ./configure to set the target location where you want the package installed. With packages building shared libraries, it's often essential to do the make install step, which it sounds as if you maybe didn't do. Sorry for being vague, these things are a bit complicated.

Categories : C

Methods of removing the youtube iframe api console error - "blocked a frame with origin..." in chrome console
I had a similar error where the JS error was: Blocked a frame with origin "https://www.youtube.com" from accessing a frame with origin "http://www.yourdomain.com". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocol/Protocols must match, YouTube has CORS (Cross Origin Resource Sharing) enabled to allow across domains. Try getting rid of the https:// in your YouTube iframe tag? You could also take a look at your closing iframe tags. Iframe tags are not singleton tags and must end with a </iframe> and not a />.

Categories : Javascript

How to identify Go program CPU usage hot spots?
Check the pprof package for programmatically acquiring profiling data. Another option is to automatically profile package tests: $ go help testflag ... -cpuprofile cpu.out Write a CPU profile to the specified file before exiting. The profiling data can be inspected using: $ go tool pprof your-binary your-profiling-data For help with the many options of the pprof tool run it without arguments: $ go tool pprof For help with the many commands of pprof, enter 'help': (pprof) help I suggest to use the svg option in the browser. It's interactive and the bottleneck paths are emphasized for easy detection. Details are available using the 'list' command, which shows the source code for a function/method together with the per-line data. Recommended reading: Profiling Go Pro

Categories : Go

Analyze memory usage of a C program
Get memory from the heap (malloc() and friends) instead of using the stack. The heap permits much larger allocations. int *bigarray = malloc(sizeof(int)*rows*columns); /* to access row r, column c */ bigarray[r*columns+c] = 42; /* equivalent method to access row r, column c */ *(bigarray+r*columns+c) = 42;

Categories : C

Correct usage from function prototype in program
int fopen (FILE* f, char* filename, char* mode) This means you should pass a pointer-to-char to argument filename, but you are passing filename[0], which is a char. The same happens with argument mode. The code below will do: FILE* f; char* filename="file.txt"; //assuming the file you want to write in is called file.txt and in the same folder with the project int t; t= fopen(f, filename, "w"); However, I think you should take some time to fully understand some basics about C. You didn't malloc any memory for the pointers, which tends to cause some runtime error. And you seem a little messed up with types. It's better to have a solid foundation before dealing with files, or there will be more problem.

Categories : C

Limiting the memory usage of a program in Linux
The fact that you’re using Wine makes no difference in this particular context, which leaves requirements 1 and 2. Requirement 2 – I do not want the process to crash once it exceeds the limit. I want it to use HDD page swap. – is known as limiting the resident set size or rss of the process, and it’s actually rather nontrivial to do on Linux, as is demonstrated by a question asked in 2010. You’ll need to set up Linux control groups (cgroups). Fortunately, Justin L.’s answer gives a brief rundown on how to do so. Note that instead of jlebar, you should use your own Unix user name, and instead of your/program, you should use wine /path/to/Windows/program.exe. Using cgroups will also satisfy your other requirements – you can start as many instances of the program a

Categories : Linux

Reduce memory usage in the below anagram program - C#
Few points I noticed: Instead of loading whole file into memory, read it word-by-word. It might make things more complex, but it will reduce memory for big files. Not that it matters for example text you provided. Instead of accumulating result output (in a), just save the words in dictionary itself, probably in the list, and output it after you run through whole file. Try using Radix Tree instead of using dictionary. I think my 2nd point here is most important in your case. 1st and 3rd point would matter if you had much bigger file with many more different words, but minimal "hits" of equal anagrams.

Categories : C#

Java clear console error: java.io.IOException: Cannot run program "clear"
There's pretty much nothing in the console related API to do a clear screen. But, I think you can achieve the same effect through println()s. A lot of putty clients clear the page like that and then scroll up. private static final int PAGE_SIZE = 25; public static void main(String[] args) { // ... clearScreen(); } private static void clearScreen() { for (int i = 0; i < PAGE_SIZE; i++) { System.out.println(); } }

Categories : Java

Usage of <= hangs the program, but < works fine (K&R C Exercise 1-20)
If you take the ++i and --i out, then wheni==ttab, you loop forever, since i never changes again. You could loop while i<ttab then add a special check for i==ttab after, or you could use a for loop which increments i, and then does i--at the end.

Categories : C

How to Communicate With a Program Through Console / C++
Since @LokiAstari pointed out, that you may don't have much experience with C++, I would recommend you to read: How to parse command line parameters. I would then use a temporary file in /tmp to communicate with the main program, which run an infinite loop, waiting for modifications to the temporary file.

Categories : C++

C# Console Program issues
Console.Read() reads a single character from standard input, and returns its ASCII value. If you press two keys, each Console.Read() call will return one of them You probably want ReadLine(), which reads an entire line of text (which you will then want to parse into an int).

Categories : C#

Use [STAThread] in a console program in C#
You can only put [STAThread] above the entry point method (not class) and only once in a library. What is your project type that you're trying to copy this code to? Does it even require the STA attribute? Is the method static? The error is saying you're putting [STAThread] on something other than an method. Post up your code.

Categories : C#

Optimizing space usage in a trie structure in a java program
First of all, separate the datastructure (your trie) from any code filling it. It just needs to hold the data in a structured form, and provide some basic functionality, that's it. Filling it should happen outside that datastructure itself so you can properly handle the streams. There is not a single good reason to have your trie fill itself by giving a path as a param. To clarify my first point - pulling the filling out of the trie: currently the streams gobble up a lot of memory inside the trie because they are held in private variables and the streams are never closed or destroyed. which means you keep the the file loaded in memory on top of the filled datastructure. Otherwise garbage collection can clean up those items just like using the arraylist. Please don't reinvent the wheel and

Categories : Java

Delete a program that are running in console of C#
You're trying to delete the folder in which your running application is in and therefore delete the program itself? Well, you have a few options. It is interesting to note as well that batch files can delete themselves. So, that also leaves you a few more options: have your C# program copy itself to a temp directory before deleting the folder, and run from there. use a batch file entirely instead of C# - having it do whatever and then delete itself afterwards. have your C# program generate and execute a batch file and then quit - leaving the batch file to clean up after the C# program exits. run a CLI command to delete your program after a specified time: Process.Start("cmd.exe", "/C ping 1.1.1.1 -n 1 -w 3000 > Nul & Del " + Application.ExecutablePath); you can use MovFileEx to

Categories : C#

unable to see the output of c++ program in the console
You may simply need to flush the output, using flush or endl. Try this: cout<<"sample text" << endl; or cout<<"sample text" << flush;

Categories : C++

Groovy Compilation error :Unrecognized Windows Sockets error
It looks like that error is a WSAEPROVIDERFAILEDINIT error. From the link: Service provider failed to initialize. The requested service provider could not be loaded or initialized. This error is returned if either a service provider's DLL could not be loaded (LoadLibrary failed) or the provider's WSPStartup or NSPStartup function failed. This might be caused by Java being launched by a wrapper, but not receiving all the correct environment variables: A quick search over at Sun's Java site (for "10106") turned up this thread: "java.net.SocketException: Unrecognized Windows Sockets error: 10106: create" at http://forum.java.sun.com/thread.jsp...hreadID=329241 The thread seems to suggest that your environment variable for "system root" might be incorrect, and that it needs t

Categories : Groovy

Python program to connect to console via telnetlib
import telnetlib # ... a_tuple = [('172.28.247.240', 66)] HOST = a_tuple[0] # do you mean to use 'a_tuple' instead of 'j'? # ... tn = telnetlib.Telnet(HOST[0], HOST[1]) # <-- pass the port, I don't think this accepts tuples of hostname/ip and port # ... Should part of your code looks like above instead? Also, I would normally use carriage return ( ) instead of new line ( ) when sending commands. Some host are picky about this.

Categories : Python

Cancelling Console.ReadKey() using code, not in-program
You can't cancel ReadKey, unless you abort the thread. (Force closing the program.) I check if a key is available using the Console.KeyAvailable property before calling ReadKey.

Categories : C#

Program to create shapes and show them on console
Just an idea how to do it. Notice, that the drawing is hidden from the shapes collection. interface Drawable { public void draw(Graphics g); } class DrawableSquare implements Drawable{ public DrawableSquare(int x, int y, int width) { ... } public void draw(Graphics g) { g.fillRect(x, y, width, width); } } class Screen { Collection<Drawable> drawables; public void paint(Graphics g) { for (Drawable dr: drawables) { dr.draw(g); } } }

Categories : Java

What is sent to the program when the user presses enter in the console?
What is sent to the terminal is 10 characters: [J][o][h][n][ ][S][m][i][t][h][ ] How the program handles it, depends on the function being used to read the input. The final character there (' ') is the indication that we hit "enter". A null terminated string is a concept internal to the program (ie string functions required it to work properly), you won't see a NULL terminator coming from stdin in your example. This is why you need to understand how the functions work that accept data from the user, if it takes the newline character, you may need to strip it. If it doesn't automatically append a null terminator, you should probably add one, etc.

Categories : C

exception of strcpy function in c++ console program
str2 is an uninitialised pointer. strcpy does not allocate memory so is currently trying to write to an arbitrary address which you don't own and very likely isn't writable by your code. You need to point str2 to valid memory before calling strcpy. str2 = (char*)malloc(str.size()+1); strcpy(str2,str.c_str()); You should also free the memory later in your program free(str2); // cannot dereference str2 after this point

Categories : C++

can't pull a string from console with java program
It looks like Java isn't expanding the asterisk: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class GetOS { public static void main(String[] args) throws IOException, InterruptedException { System.out.println(getFirstLine("/etc/*-release")); System.out.println(getFirstLine("/etc/os-release")); } public static String getFirstLine(String file) throws InterruptedException, IOException { ProcessBuilder b = new ProcessBuilder(); b.command("cat", file); Process proc = b.start(); proc.waitFor(); System.out.println(proc.exitValue()); BufferedReader is = new BufferedReader(new InputStreamReader(proc.getInputStream())); return is.readLine(); } } If you

Categories : Java

Cleanup code in Win32 console program
This is one way to do it, though I would suggest you use an event HANDLE and WaitForSingleObject, as it would tend to be considerably more "yielding". I left the high velocity spin-loop in this just for you to peg one of your cores while still seeing the handler is intercepted. I took the liberty of modifying your running state to be atomically evaluated and set respectively, as I didn't want the optimizer throwing out the eval in the main loop. #include <iostream> #include <cstdlib> #include <windows.h> // using an event for monitoring LONG running = 1; BOOL WINAPI consoleHandler(DWORD signal) { if (signal == CTRL_C_EVENT) { std::out << "Received Ctrl-C; shutting down..." << std::endl; InterlockedExchange(&running, 0);

Categories : C++

In JSP technology, what's the difference between a translation error vs a compilation error?
With in the The Life Cycle of a JSP Page Those errors while Static data is transformed into code that will emit the data into the response stream. Read docs on the same Translation and Compilation

Categories : Java

How to trully bind key in python console program in linux?
Add: stdscr.nodelay(True) To the beginning of the program. Then getch will always return right away. It'll return -1 if the user hasn't pushed anything since last time you called getch.

Categories : Python

Console program, static methods, socket becomes null
m_sock is defined internal to Main as well as at class level, You don't have to define it again in the Main, just initialize it, like: static void Main(string[] args) { m_sock= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); notice the Socket is removed. Currently your Main method is initializing a local m_sock, and that is why your class level m_sock is staying null, later when you access it in the static method you are getting the exception.

Categories : C#

Is it a bad idea to combine a GUI program and a console application into a single EXE?
In this case I would create a functional class library that is invoked from different Host projects. MyApp.WPF references MyLib as a dll...MyApp.Console references MyLib as a dll. edit I see that you already have the class library with the functionality segregated. What is the real benefit of keeping it in the same application then?

Categories : C#

how to execute console commands in a java program for node
I expect that node.exe requires text, not binary as you are using it. This means that using PrintWriter to write lines of text and BufferedReader to read lines of text would make more sense. Java has a built in Javascript interpreter. I assume you cannot use that for some reason.

Categories : Java

Console output order slows down multi-threaded program
It has nothing to do with multi-threading. It is a problem of loop optimization. I have rearranged the original code to get something minimalistic demonstrating the issue: #include <iostream> #include <chrono> #include <mutex> int main() { auto t_begin = std::chrono::high_resolution_clock::now(); for(int i=0; i<2; i++) { double d=0.0; for(int j=0; j<100000; j++) d += 1.23456; std::mutex mutex; std::lock_guard<std::mutex> lock(mutex); #ifdef SLOW std::cout << 'a' << d << std::endl; #else std::cout << d << 'a' << std::endl; #endif } auto t_end = std::chrono::high_resolution_clock::now(); std::cout << "Took : " << (static_cast<double>((t

Categories : C++



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.