Say I want to print a string with quotes around it, ( "example" ).
In Linux, doing the same thing works in the simplest case. However, is there some reason in Linux that doing this will generate a new line at the end of the command? For instance, running my program in Windows:
std::cout<<"Blah \""<<example<<"\" Blah";
In Linux I have however
Blah "
example" Blah
Is there any reason why this should be happening? (Why am I getting this newline?)
Thanks again.
The way you are doing is wrong.
"Blah "\" << example << "\"Blah";
The above is wrong. "Blah "\" have closing double quotes before the backslashed double quotes.
This should work.
std::cout<<"Blah \""<<example<<"\" Blah";
Related
I can't understand why the "\" doesn't appear when i run the program. I want to make some ASCII Art and "\" is basic for the picture i want to make.Is there any solution? I am using Code Blocks .
With C++2011 you can use raw string literals, e.g.:
std::cout << R"(\)" << '\n';
The sequence R"( starts the string and )" ends the string. If the string )" needs to be embedded into the string, you can add some string between the " and the ( which then needs to be repeated between the ) and the " to end the string.
Of course, it may just be simpler to escape the escape character and to use \\ as you already mentioned.
You have to use 2 \ since the \ character is known as an escape key, like if you want to go to the next line you have to use \n and that lets C++ know that you want to move to the next line, so every time you use the \ character, you have to type it like \
I've found it. You have to enter 2 times the "\" and then it will appear.
Working with ruby 1.9.3 --> when rendering text pdf.text "Hello \n World" it works as advertised.
However, if i pass it as a parameter from ARGV " \n " is just being displayed as text and not CR.
Checked encoding. both US-ASCII.
Any ideas?
"Hello '\n' World" - hope this helps)
Ok, I know I can do loop like this:
for (int i=1; i<=argc-1;i++) {
cout << argv[i] << endl;
}
But this way double quotes are lost, that is a string "something here" is treated as one element of the args array and quotes are lost.
Ok, I know I can assume quotes if parameter has space inside, but quotes are always lost no matter if there is space or not.
It's the shell that removes the quotes. If you want the shell to pass the quotes to you, you have to escape them:
$ ./my-program \"hello\ world\"
Note that I escape the space as well, to make it one argument.
When you need the original command line, your can use the GetCommandLine() API function.
I need to replace multiple contiguous new line/line feed characters in flex with a single new line character.
Example:
The string
"My name is blah blah \n\n\n\n
My name is blah \r\n\r\n\r\n"
Should be converted to
"My name is blah blah \n
My name is blah \n"
Hope the example makes it easier to understand.
I am using a component to render it.
I guess using regex would be the easiest way to do this, but still it would be great if people can point me out to references/examples to get this done with ease.
I am using flex 4.5.
Thanks,
Neeraj
You can use String.replace method to do the job, it's possible to use both string or regular expressions to match some part of a string value. So regarding to your question the code will look like below:
var filter: String = "My name is blah\r\r\r blah \n\n\n\r\nMy name is blah\r\n\r\r\n\n\n\r\n";
filter = filter.replace(/(\r|\n)+/g, "\n");
multiple contiguous new line/line feed characters
If you mean sequence "\r\n" then:
var myString:String = "text\r\ntext\r\ntext\r\n";
myString = myString.split("\r").join("\n").split("\n\n").join("\n");
i´m working on an application which uses readline to read commands from stdin.
It accepts "cd", and other commands which require a path as an argument. I'm having troubles with paths that include whitespaces. My objective is to somehow make readline quote the whitespaces, and autocomplete the path name after this character appears(actually, when a space is encountered, it is just skipped, and autocompletion starts from the next word).
I've been trying to achieve this, but i keep trying things and none of them work. I've managed to quote a " " into a "\ ", which is what i want. But then readline doesn't interpret this as part of the path, it just skips it, and autocompletes the next word as if there was nothing before that. Basically, i'm expecting the same behaviour as bash's autocompletion.
Any help is appreciated.
Thanks in advance!
Edit:
Alright, so i've managed to somehow accomplish what i was looking for. What i did was:
During initialization:
rl_attempted_completion_function = completition;
rl_completer_quote_characters = "\"";
rl_filename_quote_characters = " ";
completition should return a char** containing every command that matches what "text" as so far. I've ommitted that part, since it doesn't have to do with what i was asking. The important part is the rl_filename_quoting_desired = 1; which tells readline that you want your filenames to be quoted.
char **completition(const char *text, int start, int end) {
rl_filename_quoting_desired = 1;
return 0;
}
Note that what i ended up doing is what BuHHu-nyx said, just adding double quotes(") to filenames.
Try to escape not spaces but the whole path. For example:
cd "/path/to/some where"