I have made a program which reads a string from the user and store it in a vector,
but i have a small problem.
I want something that "reads" the string and if the second position of string is a number i want to store that number in an integer so as to use it..
for example:
string line;
int k;
getline(cin,line);
line[1]==k;
last command is not right but i need something that is able to do it.
string is unknown until user puts it.
**string can be mixed numbers and characters** i just need to take line[1] if only it is a number..
Thanks in advance.
string line = ":12";
int k;
stringstream ss ( line.substr(1) ); // create the stream from line, removing the first character
ss >> k; // read k from the stringstream
Please use [code][/code] tags
I don't know what you mean but in if(line[1]==k) you are comparing an int with a character.
If you want to check if the second character is a number ( digit ) use the function I mentioned above
if you run this code then it will ask you to enter a string.. I save that string in a vector.
output : 1>
2>
etc
command :s --> shows the context of the vector
command :c --> clears the vector
command :w myout.txt --> saves vector in myout.txt
command :i myout.txt
:s --> shows the index of the .txt file
i want to make the following command :
:12 --> this command will show me line 12 and whatever i write will erase the vector at 12
and repace it with the new line tha i will write.
that's why i want to connect 'if' with 'k'..