initializer fails to determine size of...

Am I writing a programme intended to read a text file and format the contents. The text file is one long line, and should be formatted such that a new line is used instead of a ',' in the text.

This is what I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* strtok example */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main () {
string line;
  ifstream myfile ("example.txt");
  if (myfile.is_open())

      getline (myfile,line);

  char str[] = line;
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",str);
  pch = strtok (str,",");
  while (pch != NULL)
  {
    printf ("%s\n",pch);
    pch = strtok (NULL, ",");
  }
  int a ;
  cin >> a;
  return 0;
}



Right now I am getting 17 C:\Dev-Cpp\Parser\Main.cpp initializer fails to determine size of `str'

I can't say that I understand this error or now to fix it. Any advice would be helpful. Clearly I am very new to this and am trying to grasp the basics while writing things I find useful.

char str[] = line;

1) This doesn't work
and
2) It's kind of stupid to do anyway...

Don't use C functions if you have C++ stuff and std::string. Look up substr() and find().
Topic archived. No new replies allowed.