473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

c++ noob

I am taking an introduction to c++ at my school. We use the
Lawrenceville Press book and studio at my school. I just downloaded
Microsoft Visual Studio 2005 for experimenting away from school.

I am trying to write a function, (with Microsoft Visual Studio), to
turn a string into an integer. The LVP studio has a library, (whos
name a cant recall) that lets me turn a C++ string into a C string,
and then use atoi() to convert it to an integer. Visual Studio, as
far as i can tell, will not let me easily do this.

I have looked at the help file, but to no avail. The help file uses
characters to turn strings into intergers, and it confuses me. What is
the difference between:
string mystring="hello world" and char *mystring ="hello
world" ????
If anyone could give me a link or a simple explination to the
difference between these two types, and/or give me some help on
turning strings into integers, I would really appreciate it.

_BG

Nov 22 '05 #1
3 1707

<ba******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
I am taking an introduction to c++ at my school. We use the
Lawrenceville Press book and studio at my school. I just downloaded
Microsoft Visual Studio 2005 for experimenting away from school.
Visual Studio contains so many "bells and whistles"
that it's difficult for the novice to discover the
C++ translator buried deep within.

Try a simpler package, or read the documentation and
learn how to use the compiler from the command line.

I am trying to write a function, (with Microsoft Visual Studio), to
turn a string into an integer. The LVP studio has a library, (whos
name a cant recall) that lets me turn a C++ string into a C string,
The standard C++ function is a member of the std::string class:
c_str().
and then use atoi() to convert it to an integer.
'atoi()' does do that, but is inherently dangerous.
See the C FAQ for details.
Visual Studio, as
far as i can tell, will not let me easily do this.
All the components are there, albeit not easy for
a beginner to discern.

Also note that here we only discuss the C++ language,
not particular compiler packages.

I have looked at the help file, but to no avail.
A good book on C++ would be a much better alternative.
See the reviews at www.accu.org for ideas and suggestions.
The help file uses
characters to turn strings into intergers, and it confuses me. What is
the difference between:
string mystring="hello world" and char *mystring ="hello
world" ????
The first creates an object of the C++ standard library
type 'string'. The second creates a pointer object and
stores as its value the address of a string literal.
The string object is modifiable, the string literal
whose address the pointer contains is not (without
undefinded behavior).


If anyone could give me a link or a simple explination to the
difference between these two types, and/or give me some help on
turning strings into integers, I would really appreciate it.


#include <iostream>
#include <sstream>
#include <string>

int main()
{
std::string s("123");
std::istringstream iss(s);
int i(0);
iss >> i;
std::cout << i << '\n'; /* prints 123 */
return 0;
}

Alternatively, look up 'std::string::c_str()'
and 'strtol()' (declared by <cstdlib>)

-Mike
Nov 22 '05 #2
thanks for the advice!
-bg

Nov 22 '05 #3
In article <11*********************@o13g2000cwo.googlegroups. com>,
<ba******@gmail.com> wrote:
I am taking an introduction to c++ at my school. We use the
Lawrenceville Press book and studio at my school. I just downloaded
Microsoft Visual Studio 2005 for experimenting away from school.

I am trying to write a function, (with Microsoft Visual Studio), to
turn a string into an integer. The LVP studio has a library, (whos
name a cant recall) that lets me turn a C++ string into a C string,
and then use atoi() to convert it to an integer. Visual Studio, as
far as i can tell, will not let me easily do this.

I have looked at the help file, but to no avail. The help file uses
characters to turn strings into intergers, and it confuses me. What is
the difference between:
string mystring="hello world" and char *mystring ="hello
world" ????
If anyone could give me a link or a simple explination to the
difference between these two types, and/or give me some help on
turning strings into integers, I would really appreciate it.


Check out http://www.comeaucomputing.com/techtalk/#atoi
http://www.comeaucomputing.com/techtalk/#stringtostring
http://www.comeaucomputing.com/techtalk/#stringvsstring
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave Williams | last post by:
First off...total noob to VB. So far have learned a lot in 1.5 days and feel fairly comfortable at throwing screens up. However, I want to start writing forms that revolve around an access...
7
by: administrata | last post by:
Is it possible? I tried... I = "John" print \ """ I used to love pizza"""
10
by: Matt Hollingsworth | last post by:
Hello, Very new to python, so a noob question. When I've written stuff in JavaScript or MEL in the past, I've always adopted the variable naming convention of using a $ as the first character...
1
by: davestrike | last post by:
I am a noob to sql and asp programming. I am working on a db for the gaming squad I am a member of. One of the pages I created is a roster list of all the squad members. Part of this roster is...
3
by: We need more power captain | last post by:
Hi, I know less than a noob, I've been asked to do some compiles in VC++ 6 without knowing too much at all. (I'm a COBOL program normally so this is all too much for me) I open VC++6, open...
2
by: Rtritell | last post by:
I dont get whats wrong with this <html> <head> <title>Random Mad Lib!</title> <script language="JavaScript"> <!-- Hide
8
by: Ivan Shevanski | last post by:
Alright heres another noob question for everyone. Alright, say I have a menu like this. print "1. . .Start" print "2. . .End" choice1 = raw_input("> ") and then I had this to determine what...
2
by: Link360 | last post by:
Im a complete noob and im proud of it. I am excited in learning everything about the C++ language. Right now im trying to make tic-tac-toe. Go ahead laugh. here is what i have so far ...
5
by: Hydrogenfussion | last post by:
Hello and thank you for reading this. I have just started to learn C++ from www.cprogramming.com,its a great site! But i do not understand some of the terms. I am using Dev-C++. Can you tell me...
1
by: Fluffy654 | last post by:
First off I am a complete noob when it comes to doing anything with servers. I'm just beginning to learn today because I need to start adding SSI to my websites. I apologise in advance if I am making...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.