Gnu debugger can't remove variable from display? [duplicate] - c++

This question already has answers here:
GDB: How to remove a variable from the auto display
(2 answers)
Closed 5 years ago.
I am working on a c++ program on linux ubuntu 16.04 and I've done a tutorial on gnu debugger.
I am having some problems with my code and as I step through it it's easier for me to compare two variables at each part fullPath and argv[1]
But once I get past that particular segment I want to remove argv[1].
I called them with the following:
display argv[1]
display fullPath
But when I try to remove argv[1] with undisplay argv[1] I get an error that reads the following:
warning: bad display number at or near 'argv[1]'
It still continues to display argv[1] unless I exit debugger and start it again without displaying it. Is there a way to fix this?
NOTE
I've also tried delete argv[1] which also doesn't work.

The undisplay command is expecting a list number, not an expression. You can see the list numbers for all your auto-display expressions by typing:
info display
Let's say that argv[1] is assigned item 3 in that list. You would then remove it with:
undisplay 3

Related

C++ console insert text into displayed text [duplicate]

This question already has answers here:
Rewinding std::cout to go back to the beginning of a line
(3 answers)
Closed 4 years ago.
How can I rewind std::cout back to beginning of line and insert text without overwriting exiting one ? Can it be done using just standard c++ functions, or do I need low-level OS functions for console to do this ?
EDIT: I'm writing a simple telnet client. So when a message is received it should be appended at the top and user imput should not be overwritten.
No, you can't do this, and it's considered useless in console.
There is a function named std::seekp for all basic_ostream based class. But when you apply this to cout, no effect at all but failbit is set.
Use std::cout << '\xd' this line will output a carriage return which will fulfill your requirement. This this line will overlap your previous entry.

How can I insert an input in sublime compiler [duplicate]

This question already has answers here:
Sublime Text with console input for c++ programs
(2 answers)
Closed 8 years ago.
I started to use sublime text 2 editor today to write c/c++ programs, but when I run this code
#include <cstdio>
int main(){
int n;
scanf("%d",&n);
printf("%d\n",n);
return 0;
}
I am expecting the compiler to ask for an input.
but instead, it just prints the initial value of (n) which is garbage.
How can i insert an input ?
I suppose what you want to do is input data in the same panel where Sublime Text show results, well friend, you can't.
The only thing you can do is configure Sublime Text for running the compiled program in an external terminal. The link chris provide you is a good start.
On the other hand when you say: expecting the compiler to ask for an input, is a conceptual error. The compiler is not whom is expecting the input. The input is being expected by the compiled program.

Getting weird error using g++ compiler [duplicate]

This question already has answers here:
Compilation error: stray ‘\302’ in program, etc
(12 answers)
Closed 8 years ago.
When I try to compile my code using g++ in terminal, I get an error:
Decoder.cpp:32:1: fout: stray ‘\302’ in program
Decoder.cpp:32:1: fout: stray ‘\262’ in program
Decoder is a class that decodes lines from an inputfile. I have no idea what these errors can be. When I look on the internet, they say it has something to do with whitespaces. No clue why! I used to write empty spaces to an output file: like this out << " ";. But I never got an error untill now.
So I went to eclipse, and my code runs fine. Back to g++ and I get the same error. Any idea why?
You've somehow ended up with a non-ASCII character (Unicode "superscript two") in line 32 of your source. Delete that character, replace it with whatever is supposed to be there (a normal 2, perhaps? or maybe nothing?), and be careful where you copy and paste code from.
There could be invisible control character on line 32. Please rewrite the complete line. That should fix your compilation issue.
You may as well refer: https://stackoverflow.com/a/6572148/815812

Why does using system("some.exe") in C++ method not work like the command line?

I am writing a program for Windows that eventually has to launch a different pre-existing .exe that sits on the same computer. It passes multiple parameters to this .exe file. I am reading the actual command and parameters and constructing the command but I also tried hard coding it with the same results. Here's the hard coded version (I picked this out of an older C program that uses the same.exe):
system("c://IQapture//dmon2_6_IHD -p2 c://IQapture//mon_table_101_Tx8.txt 11 0 0");
So in the original program inside int _cdecl main(int argc, char**argv) this use of system works. In my C++ program inside a C++ class method when I issue the command the correct program launches but it immediately puts up an error dialog stating that an error has occurred. I echo'd the system string used to launch the exe out to the console. Right after it fails, I copy and paste the same line that was echo'd and this time the exe runs without error. This is repeatable. In case it was timing related I tried adding a 10 second delay before issuing the system command but it didn't matter. Plus the original older program doesn't require a delay. This implies to me that the string is correct and the target program works. Somehow the system() invocation is different from a direct command line invocation. The program compiles and builds fine. I'm using Visual Studio 2010.
Does anyone have ideas on how to make the system() invocation work like the command line invocation?
That really doesn't look like the kind of thing that Windows would be happy with... Try it with backslashes instead:
system("c:\\IQapture\\dmon2_6_IHD -p2 c:\\IQapture\\mon_table_101_Tx8.txt 11 0 0");
If that still doesn't work, you quite likely have one of the following issues:
Your current working directory is wrong;
An environment variable is missing;
Your program is running with the wrong user permissions;
Your program is tying up a resource that the spawned process requires (eg you have not closed a file that it requires as input).
There are a lot of things to consider - the environment, the user running the program, the parent process and what's inherited... Take a look at the parameters to the CreateProcess function. Chances are your system call's invocation isn't matching the command line's (though that may not be the issue, simpler things are more likely.)
I'd advise working backwards from the error to rule out simple causes such as the environment, current directory, etc. before delving into such things as creation flags and security attributes.
You have your slashes backwards. Try:
system("c:/IQapture/dmon2_6_IHD -p2 c:/IQapture/mon_table_101_Tx8.txt 11 0 0");
You can use the backslash \ but because that is an escape sequence starter in a string (for C/C++) that is why you use two in a row. As the compiler will convert \\ into a single slahs in the string:
Thus:
system("c:\\IQapture\\dmon2_6_IHD -p2 c:\\IQapture\\mon_table_101_Tx8.txt 11 0 0");
// Is equivelent to the command line string:
> c:\IQapture\dmon2_6_IHD -p2 c:\IQapture\mon_table_101_Tx8.txt 11 0 0
But Windows has supported both types of slashes for longer than I can remember. So the following command line is equivalent.
> c:/IQapture/dmon2_6_IHD -p2 c:/IQapture/mon_table_101_Tx8.txt 11 0 0
Using '/' in a string (in C/C++) does not require escaping. So you just need to use it as is:
system("c:/IQapture/dmon2_6_IHD -p2 c:/IQapture/mon_table_101_Tx8.txt 11 0 0");

get output of system() into a variable [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Best way to capture stdout from a system() command so it can be passed to another function
In linux to get the current status of a service I wrote this code segment::
char cmd[100];
sprintf(cmd,"service %s status",argv[1]);
system(cmd);
It is running fine and it shows the output on the console like : mysql is running OR mysql is stopped
But I need this console output in a string variable. How can I get 'mysql is running' in a string variable so that I can use this string variable later.
thankx.
If you want to capture output then use popen() rather than system().