I am trying to input lines from a file. Each line is a word. I am taking the word and splitting it up, then based on the split, then putting it to a long int. For instance, i read in the word "Raindrops". I would then use substr to create a seperate string "ai". Im needing to then make "ai" into an interger based on ascii code. I have tried to cast, use stoi, stol, strtol, strtoi, and they have all failed at runtime do to invalid arguments. I feel as though this should be simple.
My next thought would be to go from a string to a string array in c++ and then each field in the string array it would individually assign ints to it. Is this the best way?
Thanks!
long int foo(int inWord){
string slice1 = inWord;
slice1 = slice1.substr(2,2);
//make the new substring into a char array?
//trying to convert to ascii
return ascii code
}
Any suggestions on how to read in a word using getline() using a char array then getting specific characters out based on their position would be helpful. thank you!
Aucun commentaire:
Enregistrer un commentaire