By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

2 basic questions about types and strings

P: n/a
Hello,

first of all I have a question about types:
When I have a method like this...

TYPE getStringValue() {
string str = "test";
return str;
}

....TYPE can't be "string" because "string" is no basic type.
I made some workaround with creatng a class Stringtype and using this
class as return type while Stringtyp contains the real string;
How is this to solve in the right way?
My second question is about string itself:

In a string I want to add the new line mark of the current operating
system to a string.

string str += "\n"; would work, but how is this to solve with std::endl?

Thanks,
Markus
Aug 8 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Aug 8, 9:53 pm, Markus Pitha <newsgroupsNOS...@pithax.netwrote:
Hello,

first of all I have a question about types:
When I have a method like this...

TYPE getStringValue() {
string str = "test";
return str;

}

...TYPE can't be "string" because "string" is no basic type.
So?
#include <string>
std::string getStringValue()
{
std::string str = "test";
return str;
}
What is problem with this?
I made some workaround with creatng a class Stringtype and using this
class as return type while Stringtyp contains the real string;
How is this to solve in the right way?

My second question is about string itself:

In a string I want to add the new line mark of the current operating
system to a string.

string str += "\n"; would work, but how is this to solve with std::endl?
what exactly you want to solve with std::endl and why? std::endl is a
manipulator - which means it is used to control the formatting during
the output. To be precise, std::endl writes a newline and also flushes
the buffer.

Thanks,
Markus

Aug 8 '07 #2

P: n/a
Neelesh Bodas wrote:
...TYPE can't be "string" because "string" is no basic type.
>
So?
#include <string>
std::string getStringValue()
{
std::string str = "test";
return str;
}
What is problem with this?
Oh, I thought it works with "string" instead of "std::string" while
using "using namespace std".
A really stupid mistake of mine. Thanks, this works now.

what exactly you want to solve with std::endl and why?
Actually I want to have my string in the following structure:

X X X X
X X X X
X X X X

That's why I want to add new line characters in the end of every line.
Markus
Aug 8 '07 #3

P: n/a
Markus Pitha wrote:
Actually I want to have my string in the following structure:

X X X X
X X X X
X X X X

That's why I want to add new line characters in the end of every line.
And using "\n" for the newlines is wrong exactly why?
Aug 8 '07 #4

P: n/a
On 2007-08-08 15:20:44 -0400, Juha Nieminen <no****@thanks.invalidsaid:
Markus Pitha wrote:
>Actually I want to have my string in the following structure:

X X X X
X X X X
X X X X

That's why I want to add new line characters in the end of every line.

And using "\n" for the newlines is wrong exactly why?
Because it's a string. '\n' is the appropriate character.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Aug 8 '07 #5

P: n/a
On Aug 8, 11:04 pm, Markus Pitha <newsgroupsNOS...@pithax.netwrote:
Neelesh Bodas wrote:

..TYPE can't be "string" because "string" is no basic type.
So?
#include <string>
std::string getStringValue()
{
std::string str = "test";
return str;
}
What is problem with this?

Oh, I thought it works with "string" instead of "std::string" while
using "using namespace std".
It *does* work with string instead of std::string while "using
namespace std;"

-N

Aug 9 '07 #6

P: n/a
Pete Becker wrote:
Because it's a string. '\n' is the appropriate character.
I don't think that's relevant in this case.
Aug 9 '07 #7

P: n/a
Juha Nieminen wrote:
And using "\n" for the newlines is wrong exactly why?
I thought due to this platform independent issue.
M.

Aug 9 '07 #8

P: n/a

Juha Nieminen <no****@thanks.invalidwrote in message...
Pete Becker wrote:
Because it's a string. '\n' is the appropriate character.

I don't think that's relevant in this case.
Don't know about the relevance. I do know

std::string line;
line.push_back( "\n" );

.....don't go on my compiler, and

line.push_back( '\n' );

..... does. <G>

--
Bob R
POVrookie
Aug 9 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.