What data type that will read in letters & numbers form fstream??

Hello;

would someone please let me know what data_type will read in a string of letters mixed with numbers using fstream :);

thanks;
closed account (3qX21hU5)
std::string... A string can hold both letters and numbers. Though if you need to any calculations with the numbers in the string you will need to extract them with a stringstream.


For example lets say you have a line in a text document that looks like "123123 Hello". You could read that line in and whatever other lines there are like so.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
    std::vector<std::string> linesOfFile;
    std::string line;

    std::ifstream readFile("testing.txt");

    // Read each line in the file and store them in a vector
    while (std::getline(readFile, line))
        linesOfFile.push_back(line);


    // Print all the lines
    for (const std::string& i : linesOfFile)
        std::cout << i << std::endl;
}
Last edited on
Topic archived. No new replies allowed.