Click here to Skip to main content
15,921,210 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: String of integers Pin
David Crow18-Sep-07 5:32
David Crow18-Sep-07 5:32 
GeneralRe: String of integers Pin
Herboren18-Sep-07 6:13
Herboren18-Sep-07 6:13 
QuestionRe: String of integers Pin
David Crow18-Sep-07 6:51
David Crow18-Sep-07 6:51 
AnswerRe: String of integers [modified] Pin
Herboren18-Sep-07 9:04
Herboren18-Sep-07 9:04 
GeneralRe: String of integers Pin
David Crow18-Sep-07 10:36
David Crow18-Sep-07 10:36 
GeneralRe: String of integers Pin
Herboren18-Sep-07 10:58
Herboren18-Sep-07 10:58 
QuestionRe: String of integers Pin
David Crow18-Sep-07 11:06
David Crow18-Sep-07 11:06 
AnswerRe: String of integers [modified] Pin
Herboren18-Sep-07 11:17
Herboren18-Sep-07 11:17 
Holy shat dude it worked. you are the bomb digitty. Heh I knew I could get user input by doing cin >> string; which normally a string is a chain of characters I guess I should say symbols and I thought the string had to be converted to integers first before storing them into and array. yeah I know char's can be stored in arrays to but I had planned on adding different numerals to each int stored in the array, so i assumed i wouldnt be able to add numberals to char's stored in the array, thats like saying 1 + a or 2 + b which then would result in an error of some sort. But it worked perfectly all thanks to you. sorry if i may have sounded a little edgy, it was out of my perspective which is why i was not understanding.

Okay so the part I dont understand is the "- '0'" when converting the str to the array. Awesome im glad we completed that. Now here is another doosy. I need to create an array based on the amount of symbols in the str, so instead of pre.creating the 'aArray[5]' im using the strlen(str.c_str()) to count the number of symbols in the str from the users input. this is my code so far:

<br />
// ArrayInput.cpp : Defines the entry point for the console application.<br />
//<br />
<br />
#include "stdafx.h"<br />
#include <string><br />
#include <iostream><br />
#include <conio.h><br />
using namespace std;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
	string str;<br />
	int aArray[5];<br />
	int n;<br />
<br />
	cout << "Input a 5-digit number: "; <br />
	<br />
        <br />
	cin >> str;<br />
       <br />
        aArray[0] = str[0] - '0';<br />
	aArray[1] = str[1] - '0';<br />
	aArray[2] = str[2] - '0';<br />
	aArray[3] = str[3] - '0';<br />
	aArray[4] = str[4] - '0';<br />
<br />
        //strlen()<br />
	cout << "The length of " << str << " is: " << strlen( str.c_str()) << endl;<br />
<br />
	_getch(); <br />
	return 0;<br />
}<br />
<br />
<br />

-- modified at 17:54 Tuesday 18th September, 2007
GeneralRe: String of integers Pin
David Crow19-Sep-07 7:58
David Crow19-Sep-07 7:58 
Questioncode for opening,closing and saving an image file Pin
itsgood12317-Sep-07 14:23
itsgood12317-Sep-07 14:23 
AnswerRe: code for opening,closing and saving an image file Pin
Sarath C17-Sep-07 15:49
Sarath C17-Sep-07 15:49 
QuestionRe: code for opening,closing and saving an image file Pin
Mark Salsbery17-Sep-07 18:22
Mark Salsbery17-Sep-07 18:22 
AnswerRe: code for opening,closing and saving an image file Pin
Hamid_RT18-Sep-07 3:15
Hamid_RT18-Sep-07 3:15 
QuestionHow to switch the views by CButton cointrol on CFormview view in MDI Pin
llkkxx17-Sep-07 13:07
llkkxx17-Sep-07 13:07 
AnswerRe: How to switch the views by CButton cointrol on CFormview view in MDI Pin
Vaclav_17-Sep-07 16:10
Vaclav_17-Sep-07 16:10 
QuestionRe: How to switch the views by CButton cointrol on CFormview view in MDI Pin
Nelek17-Sep-07 20:14
protectorNelek17-Sep-07 20:14 
QuestionRe: How to switch the views by CButton cointrol on CFormview view in MDI Pin
Nelek17-Sep-07 20:00
protectorNelek17-Sep-07 20:00 
AnswerRe: How to switch the views by CButton cointrol on CFormview view in MDI Pin
Vaclav_18-Sep-07 10:23
Vaclav_18-Sep-07 10:23 
GeneralAbout the assertion Pin
Nelek18-Sep-07 21:23
protectorNelek18-Sep-07 21:23 
QuestionWhere does the application's code go? Pin
daniel3343317-Sep-07 11:33
daniel3343317-Sep-07 11:33 
AnswerRe: Where does the application's code go? Pin
David Crow17-Sep-07 11:54
David Crow17-Sep-07 11:54 
AnswerRe: Where does the application's code go? Pin
Mark Salsbery17-Sep-07 12:23
Mark Salsbery17-Sep-07 12:23 
QuestionCreating "light" backups of Visual Studio projects... Pin
@largeinsd17-Sep-07 11:14
@largeinsd17-Sep-07 11:14 
AnswerRe: Creating "light" backups of Visual Studio projects... Pin
bob1697217-Sep-07 18:00
bob1697217-Sep-07 18:00 
GeneralRe: Creating "light" backups of Visual Studio projects... Pin
@largeinsd18-Sep-07 7:01
@largeinsd18-Sep-07 7:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.