LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2009, 09:55 AM   #1
AndrewY
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Rep: Reputation: 0
std::wstring problem in simple program


Hi All,
I have a problem with wstring, maybe someone had similar problem.
When I trying to create wstring object:

Quote:
std::wstring testString(L"Simple string");
created object testString have invalid length, i.e. when I get length after creating object:
Quote:
testString.length()
it returns some dummy number (thousands, millions). I programming under Ubuntu, and my gcc version is 4.3.3.
I'm new in Linux programming. I know that it is need to post code to the forum when asking the question, but the problem is so simple, that it is nothing to post, just main function, and object of wstring type.
It is interesting that with std::string object everything is ok. Even if I create wstring object with empty string
Quote:
std::wstring emptyString(L"")
object also have invalid length, emptyString.clear() - also doesn't help.

I will be very thankful for any help in this issue.

P.S. sorry for grammatical and syntax errors, English is not my native language.
 
Old 09-30-2009, 11:41 AM   #2
carbonfiber
Member
 
Registered: Sep 2009
Location: Sparta
Posts: 237

Rep: Reputation: 46
Hello. Perhaps posting the actual code will prove fruitful. In hope to convince you to do this, try to see how this behaves on your system (first) :

Code:
#include <iostream>

int main()
{
        std::wstring s(L"carbonfiber");
        std::cout << s.length() << std::endl;
}

Last edited by carbonfiber; 09-30-2009 at 11:58 AM.
 
Old 09-30-2009, 12:14 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
whats the L for?
 
Old 09-30-2009, 01:40 PM   #4
AndrewY
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by carbonfiber View Post
Hello. Perhaps posting the actual code will prove fruitful. In hope to convince you to do this, try to see how this behaves on your system (first) :

Code:
#include <iostream>

int main()
{
        std::wstring s(L"carbonfiber");
        std::cout << s.length() << std::endl;
}
Thanks guys, I already have solved this "problem"... It was very stupid thing...
I use NetBeans, and it is possible to watch expressions like: "someString.length()" in Watch window in process of debug, and you get some value, but actually it shows pointer on function in decimal form, but not value returned by this function...

Yes, I know, I stupid...
Anyway, thank you for your help and your time.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem when running simple c program ryellamr Linux - Newbie 3 06-06-2009 02:38 PM
C++ simple problem, doesn't recognize some std::cout itz2000 Programming 3 06-28-2007 08:18 PM
simple C program problem speel Programming 14 02-27-2005 05:08 PM
simple C program problem mined Programming 2 05-08-2004 05:42 AM
simple program big problem antken Programming 3 09-15-2002 10:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration