-3
この単純なtxtファイルを印刷しようとしています。それはコードごとに成功しているので正しく開かれますが、そこに確かにデータがある場合は「0」になります。エラー:C++でのtxtファイルの印刷のみ "0"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main(){
struct item{
string item;
string type;
int price;
};
ifstream data("messageBoard.txt");
data.open("messageBoard.txt");
if (data.is_open()){
cout<<"success"<<endl;
}
cout<<data<<endl; //shouldn't think just print the entire file? It
//is only printing 0, and I am also getting "success" printed as well
while(getline(data, word, '\r')){
cout<<"here"<<endl;
stringstream ss;
int wordindex=0;
if(lineindex>0){
ss<<word;
いいえ、いいえ。起こらなければならないことを仮定しないでください。使用する関数のドキュメントを参照してください。ファイルを印刷することはできません。その内容を印刷することができます。コンテナに格納されているコンテンツ(文字列など)を取得して印刷します。 – DeiDei
getlineを使用してデータ文字列を格納していますが、ループがスキップされています。 – grilam14