(warning) multi-character character constant

Hi,

I'm writing my first programme, and I don't understand this error. I've looked up some information about it, but I can't seem to understand it.

Here's my code:
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
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;

int main () {
  string line;
  string word;
  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while ( myfile.good() )
    { 
      cin.ignore(256, '\n');
      getline (myfile,line);
      for ( int i = 0 ; i < line.length(); i++)
          if ( line[i] == ': :' )
             '/n'
      cout << line << endl;
      cin.get();
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 

  return 0;
}


The error currently occurs at cout << line << endl;

I would like to understand the error itself and how it applies to my code.

Any assistance would be appreciated
if ( line[i] == ': :' )

I think the problem is here. ': :' is a character constant as it is contained in single inverted commas. However, you have put three characters inside it. A character constant must contain one character only.

'/n'
What is this for? It doesn't seem to do anything and the semicolon is missing. (Also, is this supposed to be an escaped newline character '\n'?)
Hi there,

Thank you for the reply.

I put the semicolon after '/n' and changed '/n' to '\n' and no longer receive the error.

However, my programme still isn't doing what it's supposed to.

The programme is intended to read a txt file (example.txt). The file contains extremely long lines of text. Where a new line should be, the text file contains the characters : :

The programme should be finding those : : instances and creating a new line in the output instead.

Although I get no errors now, the programme does not create a new line instead of the : :. It merely outputs the whole long line.
Firstly, I don't think line[i] == ': :' does what you are expecting.

The single quote marks are for characters, and you are checking a single character of your string for three characters. Clearly this doesn't make sense ;)

Instead you need to compare three characters of your line variable to the string literal ": :".

If you want more advice on how to do this, I might be able to help. But perhaps you should read some of this first:
http://www.cplusplus.com/reference/string/string/

As for replacing the ": :" with a newline character, you may need to rethink your method for that too. Just writing a line '\n'; does absolutely nothing :(
Last edited on
Topic archived. No new replies allowed.