Reading Strings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • compman9902
    New Member
    • Mar 2007
    • 105

    Reading Strings

    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:
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <sstream>
    #include <string.h>
    using namespace std;
    int main()
    {
    string input;
    int position;
    char letter;
    cin  >> input;
    original[position] = letter;
    ...
    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
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    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.

    Comment

    • compman9902
      New Member
      • Mar 2007
      • 105

      #3
      Originally posted by DeMan
      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:
      Code:
      original[position] = letter;
      original = "aAbBcC";
      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

      Comment

      • DeMan
        Top Contributor
        • Nov 2006
        • 1799

        #4
        try:
        Code:
        letter = original[position];

        Comment

        • Roonie
          New Member
          • Mar 2007
          • 99

          #5
          (and put it after
          Code:
          original = "aAbBcC";
          position = 2;
          )

          Comment

          • compman9902
            New Member
            • Mar 2007
            • 105

            #6
            Originally posted by DeMan
            try:
            Code:
            letter = original[position];
            Thank you very much, it worked perfectly.
            Such a simple solution to a seemingly complex problem
            Thanks again

            Comment

            • DeMan
              Top Contributor
              • Nov 2006
              • 1799

              #7
              No worries, any time!!

              Comment

              Working...