Re: Strange Error with Glib::ustring
- From: Krzesimir Nowak <qdlacz gmail com>
- To: Gtk MailingList <gtkmailinglistgreesce googlemail com>
- Cc: gtkmm-list gnome org
- Subject: Re: Strange Error with Glib::ustring
- Date: Sun, 19 Dec 2010 20:31:06 +0100
On Sun, 2010-12-19 at 19:41 +0100, Gtk MailingList wrote:
> When i try to compile this code:
>
>
> #include <iostream>
>
> #include <glibmm.h>
>
> int main(int argc, char *argv[])
> {
> Glib::ustring mystring = "Hallo Welt";
>
> std::string::size_type stelle = mystring.find(" ");
>
> if ( stelle < mystring.length() )
> {
> std::cout << stelle << std::endl;
> mystring.insert(stelle,"\");
> }
> return 0;
> }
>
Backslash in strings works as escaping character, so if you want to have
a string containing only backslash, you have to write "\\". In "\"
second quotes are escaped, so they become a part of string, not a string
terminator - that's why compiler is complaining about missing
terminator.
>
> Compile command:
>
> g++ main.cc -pthread -I/usr/include/glibmm-2.4 -I/usr/lib/glibmm-2.4/include
> -I/usr/include/sigc++-2.0 -I/usr/lib/sigc++-2.0/include
> -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -pthread -lglibmm-2.4
> -lgobject-2.0 -lsigc-2.0 -lgthread-2.0 -lrt -lglib-2.0 -o replaceString
>
> I get this error:
>
> main.cc:14: warning: missing terminating " character
> main.cc:14: error: missing terminating " character
> main.cc: In function ‘int main(int, char**)’:
> main.cc:15: error: expected primary-expression before ‘}’ token
> main.cc:15: error: expected ‘;’ before ‘}’ token
>
>
> In this little program i try to replace all spaces in the string with "\ ".
> Because if you use a space character in a path on the command line it
> doesn't work. You must always use "/home/user/some\ directory/second\
> directory" instead of "/home/user/some directory/second directory". Maybe
> you have an better idea to solve this problem.
No need to use Glib::ustring here - in gtkmm std::string is used for
paths. Also put it into a while loop, because there can be more than one
space.
>
>
> Thott Chief
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]