When using the ifstream class to read words from an input file, I used the following expression:
#include <iostream>
#include <fstream>
int main(int argc, char *argv[])
{
std::ifstream inputStream(myFile.txt);
std::string myString;
myFile.open()
while(myFile.good())
{
myFile >> myString;
printf("%s \n", myString);
}
return 0;
}
MyFile.txt content: "This is a simple program."
It is compiled and executed, as expected, using the g ++ compiler.
However, the same code compiled using msvc 2008 returns an error in the extraction operator (→), requiring me to replace std :: string with either an initialized array of characters, or any of the supported types. This threw me away as I expected that using the standard library would be the same for all implementations.
I understand the compilation error and know how to fix it using c_str ().
, , - , .
starndard!!
EDIT: . myFile.txt.