Storing user input

Hi everyone,

I'm trying to build a program where the user inputs a string that has an int, and a char.
I'm trying to store the int in a register given by the char but I have no idea how to do this.
I separated the string input into a vector<string> so I can use each word separately but I'm not sure what to do next.
Ex.

> 3 a
3 has been stored in register a.

Thanks for any help and sorry for the confusing question!
__asm
{
mov eax, var
}

Just kidding. What exactly do you mean by register?
That normally means an internal piece of the CPU where data is processed at the lowest level. Is there a "register" class you have written, or are you referring to some other storage device / concept?

vector<string> s;
s[0][1] //the second character of the first string in this construct. Is this what you need?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>
#include <cctype>
#include <sstream>

int main()
{
    std::string myString {};
    std::cout << "Enter your string \n";
    getline(std::cin, myString);
    std::string myIntString{}, myCharString{};
    for (const auto& elem : myString)
    {
        //separate the digits and characters of the string
        if(isdigit(elem))myIntString += elem;
        if(isalpha(elem))myCharString += elem;
    }
    std::cout << "MyIntString " << myIntString << "\n";
    std::cout << "MyCharString " << myCharString << "\n";

    //to convert the digits into an int use std::istringstream
    std::istringstream stream(myIntString);
    int myIntInt;
    if(stream) stream >> myIntInt;
    std::cout << "MyIntInt " << myIntInt << "\n";
}
Topic archived. No new replies allowed.