Uncertain output of C++ String Concatenation Program
The below program is giving unpredictable and wrong output when I compile with g++ under Ubuntu OS , tried with the complier avilable with Ubuntu 8.04 and Ubuntu 10.04 LTS.
But it works fine when complied and ran Redhat g++ 3.4.6
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {
vector<string> v;
ifstream in("Fillvector.cpp");
string line;
//fflush (stdin);
//fflush (stdout);
while(getline(in, line)){
v.push_back(line); // Add the line to the end
}
string bigstring = "Hello";
// Add line numbers:
for(int i = 0; i < v.size() ;i++){
bigstring = bigstring + v[i];
}
cout <<" Big String " << endl;
cout << bigstring <<endl;
} ///:~
Its very confusing and request for help.