PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > How to make a CString to 2 lines?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to make a CString to 2 lines?

Réponse
 
LinkBack Outils de la discussion
Vieux 09/12/2007, 19h32   #1
Donos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to make a CString to 2 lines?

I have a CString with 100 characters. Now i want to make that to 2
lines.

For example,

CString str = "This is just a test to find out how to break a
cstring";

I want this CString in the following format,

CString str1 = This is just a test to find
out how to break a cstring

ie, it should come in 2 lines.

I tried using line break (\n). But that doesn't work.

This was the code that i used.,

CString str = "This is just a test to find out how to break a
cstring";

int i = str.GetLength();

CString str1 = str.Left(i/2);

str1 += '\n';

str1+= str.Right(i/2);

str = str1; // But this is not working. It's not coming in 2 lines.

Is there any other way i can do this?
  Réponse avec citation
Vieux 09/12/2007, 19h46   #2
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to make a CString to 2 lines?

On 2007-12-09 20:32, Donos wrote:
> I have a CString with 100 characters. Now i want to make that to 2
> lines.


CString is not part of the C++ standard library and thus off-topic in
this group, try asking in a group for Windows programming or MFC. Line-
breaks on Windows is usually represented by two characters, first a
carriage return and then a linefeed (\r\n), you could try using that.

--
Erik Wikström
  Réponse avec citation
Vieux 09/12/2007, 21h44   #3
Daniel T.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to make a CString to 2 lines?

Erik Wikström <Erik-wikstrom@telia.com> wrote:
> On 2007-12-09 20:32, Donos wrote:


> > I have a CString with 100 characters. Now i want to make that to 2
> > lines.

>
> CString is not part of the C++ standard library and thus off-topic in
> this group, try asking in a group for Windows programming or MFC. Line-
> breaks on Windows is usually represented by two characters, first a
> carriage return and then a linefeed (\r\n), you could try using that.


As I understand it, the \n "character" is defined as whatever it takes
to break a string into two lines.

Run time libraries may convert between the newline character and some
other character(s) (or lack of characters) during execution (such as
compacting the carriage return/line feed combination into the newline
character or generating the newline character at the end of a logical
record or transforming between various record separators and the
newline character).
(http://www.osdata.com/topic/language/cplus.htm)
  Réponse avec citation
Vieux 09/12/2007, 21h47   #4
Daniel T.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to make a CString to 2 lines?

Donos <donguy76@gmail.com> wrote:

> I have a CString with 100 characters. Now i want to make that to 2
> lines.
>
> For example,
>
> CString str = "This is just a test to find out how to break a
> cstring";
>
> I want this CString in the following format,
>
> CString str1 = This is just a test to find
> out how to break a cstring
>
> ie, it should come in 2 lines.
>
> I tried using line break (\n). But that doesn't work.
>
> This was the code that i used.,
>
> CString str = "This is just a test to find out how to break a
> cstring";
>
> int i = str.GetLength();
>
> CString str1 = str.Left(i/2);
>
> str1 += '\n';
>
> str1+= str.Right(i/2);
>
> str = str1; // But this is not working. It's not coming in 2 lines.
>
> Is there any other way i can do this?


What do you mean by "coming in 2 lines"? What does the following print
on the screen?

#include <string>

int main() {
std::string str = "This is just a test to find\nout how to break a
cstring.";
cout << str;
}
  Réponse avec citation
Vieux 10/12/2007, 01h59   #5
Sarath
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to make a CString to 2 lines?

On Dec 10, 4:32 am, Donos <dongu...@gmail.com> wrote:
> I have a CString with 100 characters. Now i want to make that to 2
> lines.
>
> For example,
>
> CString str = "This is just a test to find out how to break a
> cstring";
>
> I want this CString in the following format,
>
> CString str1 = This is just a test to find
> out how to break a cstring
>
> ie, it should come in 2 lines.
>
> I tried using line break (\n). But that doesn't work.
>
> This was the code that i used.,
>
> CString str = "This is just a test to find out how to break a
> cstring";
>
> int i = str.GetLength();
>
> CString str1 = str.Left(i/2);
>
> str1 += '\n';
>
> str1+= str.Right(i/2);
>
> str = str1; // But this is not working. It's not coming in 2 lines.
>
> Is there any other way i can do this?


This an offtopic to this group.
Probably you may be needed to give "\r\n" (carriage return and new
line) to make in two lines. You can use the Insert or another useful
interface to insert the desired characters inbetween the string. So
that you can avoid creating temporary objects.

Regards,
Sarath
  Réponse avec citation
Vieux 10/12/2007, 09h09   #6
Rolf Magnus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to make a CString to 2 lines?

Daniel T. wrote:

> Erik Wikström <Erik-wikstrom@telia.com> wrote:
>> On 2007-12-09 20:32, Donos wrote:

>
>> > I have a CString with 100 characters. Now i want to make that to 2
>> > lines.

>>
>> CString is not part of the C++ standard library and thus off-topic in
>> this group, try asking in a group for Windows programming or MFC. Line-
>> breaks on Windows is usually represented by two characters, first a
>> carriage return and then a linefeed (\r\n), you could try using that.

>
> As I understand it, the \n "character" is defined as whatever it takes
> to break a string into two lines.


Not exactly. It's defined as one signle character. The transformation
happens when doing file I/O in text mode.

  Réponse avec citation
Vieux 10/12/2007, 13h31   #7
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to make a CString to 2 lines?

On Dec 9, 8:46 pm, Erik Wikström <Erik-wikst...@telia.com> wrote:
> On 2007-12-09 20:32, Donos wrote:


> > I have a CString with 100 characters. Now i want to make
> > that to 2 lines.


> CString is not part of the C++ standard library and thus
> off-topic in this group, try asking in a group for Windows
> programming or MFC. Line- breaks on Windows is usually
> represented by two characters, first a carriage return and
> then a linefeed (\r\n), you could try using that.


It wouldn't be C++ if that were the case. In C++, a line is a
sequence of printable characters, terminated by a '\n'
character.

Any other representation of a new line is purely external to the
program, and is mapped in std::filebuf, if the file is opened in
text mode.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
  Réponse avec citation
Vieux 10/12/2007, 18h59   #8
Tadeusz B. Kopec
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to make a CString to 2 lines?

On Mon, 10 Dec 2007 05:31:36 -0800, James Kanze wrote:

> On Dec 9, 8:46 pm, Erik Wikström <Erik-wikst...@telia.com> wrote:
>> On 2007-12-09 20:32, Donos wrote:

>
>> > I have a CString with 100 characters. Now i want to make that to 2
>> > lines.

>
>> CString is not part of the C++ standard library and thus off-topic in
>> this group, try asking in a group for Windows programming or MFC. Line-
>> breaks on Windows is usually represented by two characters, first a
>> carriage return and then a linefeed (\r\n), you could try using that.

>
> It wouldn't be C++ if that were the case. In C++, a line is a sequence
> of printable characters, terminated by a '\n' character.
>
> Any other representation of a new line is purely external to the
> program, and is mapped in std::filebuf, if the file is opened in text
> mode.


It's true if he tries to output his CString to a file, but maybe he tries
to show it on some label or text box.

--
Tadeusz B. Kopec (tkopec@NOSPAMPLEASElife.pl)
Horner's Five Thumb Postulate:
Experience varies directly with equipment ruined.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,20317 seconds with 16 queries