I have read many suggestions, I actually copied one, and I cannot convert from file of strings to integers. If I create my own set of integers (mystring) within the IDE, the conversion works nicely. So, I am messing up something wrt the "fileIn" process.
I need to convert the file from a line of strings to integers that I will eventually import into an array or a vector for analysis. The numbers in the file are "23, 34 56" integers and with a single space between them.
Wen I run the code, I get nothing unless I am streaming directly from filein to cout.
Here is my code. By the way, I am new to C++ and teaching myself.
For a second, after reading, I thought it was supposed to be outfile. I am very new to C++. In fact, I am teaching myself and the only language I know so far.
The numbers in the file are double integers and with a single space between them.
double integers? it can be either double or integer but in any case why go through the std::string route instead of reading the numbers from the file into double or integer variables directly?
Yeah, bad choice of words on my behalf. I meant "23" instead of "1" or "123".
I believe I also mentioned that I am new to C++. Can you explain your statement a little more. How can I read an integer? I am aware of get() (character) and getline(), and extraction.
I just used your suggestion and had a blank screen. I forgot to mention, sorry, that the begining of my file has some type of symbols for some reason. Could the symbols, something that might have happened from my copy and paste, be causing the problem. I will create another text file and see.
1 2 3 4 5 6 7
while (fileIn >> num)
{
myVec.push_back(num);
}
for (constauto& elem : myVec)std::cout << elem << "\n";
I just created a text file myself, did not copy and paste, and it worked. It is a lot of numbers and I would rather copy and paste but I might have to enter each one by one because some symbols were inserted before my first number.