472,981 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 software developers and data experts.

2 basic questions about types and strings

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
8 1200
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
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
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
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
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steven O. | last post by:
First, this may not be the correct newsgroup. I have some relatively basic questions on SQL. I tried to find a newsgroup that was specifically just about SQL, and was surprised to find that all...
44
by: Truble | last post by:
Visual Studio .NET is not more efficient to write than VB6. I can write a VB6 App at least twice as fast as in .NET. Why did Microsoft ruin the syntax advantage of VB6 in .NET?
41
by: Psykarrd | last post by:
I am trying to declare a string variable as an array of char's. the code looks like this. char name; then when i try to use the variable it dosn't work, however i am not sure you can use it...
3
by: p988 | last post by:
Learning C# is much tougher than I expected...Please help me by answering the following questions! Thank you in advance! 1. Are all Enumerations type Value type? 2. The line, RegistryKey...
14
by: luis | last post by:
Are basic types (int, long, ...) objetcs or not? I read that in C# all are objects including basic types, derived from Object class. Then in msdn documentation says that boxing converts basic...
4
by: LCAdeveloper | last post by:
I have had to move to Visual Studio.NET Pro. from Visual Basic 4.0 and am now starting to re-write our code. I was a bit surprised to find that Visual Basic.NET no longer supports fixed length...
4
by: Peter Morris [Droopy eyes software] | last post by:
Hi all, I have some basic WebService questions #1 Let's say I have a business class named "Customer". The customer would be able to log in and update their personal information like so void...
23
by: TefJlives | last post by:
Hi all, I'm learning a bit about C, and I have a few questions. I'm not trying to insult C or anything with these questions, they're just honestly things I don't get. It seems like pointers...
12
by: Gilbert | last post by:
H, i'm starting with asp.net/vb.net and have some questions about arrays and collections: 1) what's the difference between: dim x() as string and dim x as array
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.