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

Reading Strings

compman9902
100+
P: 105
Thank you for reading this discussion, your help is greatly appreciated.
My problem is that I am trying to make a program that reads a string and one by one picks the letter and gives it the preassigned integer.
Everything is going great, the only problem is that I cannot seem to get my program to read the string peice by peice. Here is the code:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <sstream>
  6. #include <string.h>
  7. using namespace std;
  8. int main()
  9. {
  10. string input;
  11. int position;
  12. char letter;
  13. cin  >> input;
  14. original[position] = letter;
  15. ...
The only part of the code that is giving me trouble is the "original[position] = letter;" part.
Again, thank you for your time and effort.

--Parker Woods
Mar 21 '07 #1
Share this Question
Share on Google+
6 Replies


DeMan
100+
P: 1,806
I'm afraid you may have to post some more code, it is not clear where letter, position or original are set/initialised, and since you think the problem may be at a line that involves all three, it would be nice to be able to trace what they all should be.
Mar 21 '07 #2

compman9902
100+
P: 105
I'm afraid you may have to post some more code, it is not clear where letter, position or original are set/initialised, and since you think the problem may be at a line that involves all three, it would be nice to be able to trace what they all should be.
They are all variable. But for example's sake, I will do this:
Expand|Select|Wrap|Line Numbers
  1. original[position] = letter;
  2. original = "aAbBcC";
  3. position = 2;
The only problem is that I cannot get "letter" to equal "b".
I just need help on how to do that

--Parker Woods
Mar 21 '07 #3

DeMan
100+
P: 1,806
try:
Expand|Select|Wrap|Line Numbers
  1. letter = original[position];
  2.  
Mar 21 '07 #4

Roonie
P: 99
(and put it after
Expand|Select|Wrap|Line Numbers
  1. original = "aAbBcC";
  2. position = 2;
)
Mar 21 '07 #5

compman9902
100+
P: 105
try:
Expand|Select|Wrap|Line Numbers
  1. letter = original[position];
  2.  
Thank you very much, it worked perfectly.
Such a simple solution to a seemingly complex problem
Thanks again
Mar 21 '07 #6

DeMan
100+
P: 1,806
No worries, any time!!
Mar 21 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.