Hi, everybody,
Recently, I tried to read from a tsv file then
write in other multiple files.
I don't understand why the error is like this :
2_convert.C: In function `int main()':
2_convert.C:31: error: 'struct std::stringstream' has no member named 'c_str'
Thanks a lot in advance!
Following is the code,
1 #include <iostream>
2 #include <sstream>
3 #include <fstream>
4 #include <vector>
5 #include <string>
6 #include <cstring>
7
8 using namespace std;
9
10 int main ()
11 {
12 ifstream inFile ("test_4.tsv");
13 //ofstream outFile("out.tsv");
14 string line;
15 int linenum = 0;
16 while (getline (inFile, line))
17 {
18 linenum++;
19 if(linenum >= 22)
20 {
21 //cout << "\nLine #" << linenum << ":" << endl;
22 istringstream linestream(line);
23 string item;
24 int itemnum = 0;
25 while (getline (linestream, item, ' '))
26 {
27 itemnum++;
28 stringstream sstrm;
29 sstrm << itemnum << ".tsv";
30 //cout<<sstrm;
31 ofstream outFile(sstrm.c_str());
32 if ((itemnum%2)!=0)
33 {
34 outFile << "Item #" << (itemnum/2)+1 << ": " << item ;
35 }
36 else outFile<<" "<<item<<endl;
37 outFile.close();
38 }
39 }//end of if(linenum>>22)
40 }
41 return 0;
42 }
Try this:
31 ofstream outFile(sstrm.str().c_str());
It worked, many thanks for your help ! : )